diff options
| author | Randy Morgan <[email protected]> | 2012-10-14 11:34:51 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-14 11:34:51 +0900 |
| commit | a441bc1ff24c5b238203adb49b6e7ce208d5dabf (patch) | |
| tree | 770da3a7384636a4cc0c35ff443d212a1ef47912 /lib/axlsx/drawing/pic.rb | |
| parent | e4d4538e1ea15b6aff9e4ef3fbc47c2e29ceb8be (diff) | |
| download | caxlsx-a441bc1ff24c5b238203adb49b6e7ce208d5dabf.tar.gz caxlsx-a441bc1ff24c5b238203adb49b6e7ce208d5dabf.zip | |
Refactored to use use options parser.
Diffstat (limited to 'lib/axlsx/drawing/pic.rb')
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 3eb99e7d..9375f20c 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -5,6 +5,26 @@ module Axlsx # @see Worksheet#add_image class Pic + include Axlsx::OptionsParser + + # Creates a new Pic(ture) object + # @param [Anchor] anchor the anchor that holds this image + # @option options [String] name + # @option options [String] descr + # @option options [String] image_src + # @option options [Array] start_at + # @option options [Intger] width + # @option options [Intger] height + def initialize(anchor, options={}) + @anchor = anchor + @hyperlink = nil + @anchor.drawing.worksheet.workbook.images << self + parse_options options + start_at(*options[:start_at]) if options[:start_at] + yield self if block_given? + @picture_locking = PictureLocking.new(options) + end + # allowed file extenstions ALLOWED_EXTENSIONS = ['gif', 'jpeg', 'png', 'jpg'] @@ -12,7 +32,6 @@ module Axlsx # @return [String] attr_reader :name - # A description of the picture # @return [String] attr_reader :descr @@ -29,26 +48,6 @@ module Axlsx # The picture locking attributes for this picture attr_reader :picture_locking - # Creates a new Pic(ture) object - # @param [Anchor] anchor the anchor that holds this image - # @option options [String] name - # @option options [String] descr - # @option options [String] image_src - # @option options [Array] start_at - # @option options [Intger] width - # @option options [Intger] height - def initialize(anchor, options={}) - @anchor = anchor - @hyperlink = nil - @anchor.drawing.worksheet.workbook.images << self - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" - end - start_at(*options[:start_at]) if options[:start_at] - yield self if block_given? - @picture_locking = PictureLocking.new(options) - end - attr_reader :hyperlink # sets or updates a hyperlink for this image. @@ -136,8 +135,8 @@ module Axlsx use_one_cell_anchor unless @anchor.is_a?(OneCellAnchor) @anchor.height = v end - - # This is a short cut method to set the start anchor position + + # This is a short cut method to set the start anchor position # If you need finer granularity in positioning use # graphic_frame.anchor.from.colOff / rowOff # @param [Integer] x The column @@ -148,7 +147,7 @@ module Axlsx @anchor.from.row = y @anchor.from end - + # noop if not using a two cell anchor # @param [Integer] x The column # @param [Integer] y The row @@ -178,7 +177,7 @@ module Axlsx str << '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></xdr:spPr></xdr:pic>' end - + private # Changes the anchor to a one cell anchor. @@ -186,7 +185,7 @@ module Axlsx return if @anchor.is_a?(OneCellAnchor) swap_anchor(OneCellAnchor.new(@anchor.drawing, :from => @anchor.from)) end - + #changes the anchor type to a two cell anchor def use_two_cell_anchor return if @anchor.is_a?(TwoCellAnchor) @@ -202,6 +201,5 @@ module Axlsx @anchor.drawing.anchors[@anchor.drawing.anchors.index(@anchor)] = new_anchor @anchor = new_anchor end - end end |
