lib/axlsx/drawing/two_cell_anchor.rb in axlsx-1.3.6 vs lib/axlsx/drawing/two_cell_anchor.rb in axlsx-2.0.0
- old
+ new
@@ -3,10 +3,12 @@
# This class details the anchor points for drawings.
# @note The recommended way to manage drawings and charts is Worksheet#add_chart. Anchors are specified by the :start_at and :end_at options to that method.
# @see Worksheet#add_chart
class TwoCellAnchor
+ include Axlsx::OptionsParser
+
# A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
# @return [Marker]
attr_reader :from
# A marker that returns the to cell anchor. The default to column and row are 5 and 10 respectively
# @return [Marker]
@@ -32,26 +34,27 @@
# @option options [Array] :end_at the col, row to end at
def initialize(drawing, options={})
@drawing = drawing
drawing.anchors << self
@from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
+ parse_options options
end
# sets the col, row attributes for the from marker.
# @note The recommended way to set the start position for graphical
# objects is directly thru the object.
# @see Chart#start_at
- def start_at(x, y)
- set_marker_coords(x, y, from)
+ def start_at(x, y=nil)
+ from.coord x, y
end
# sets the col, row attributes for the to marker
# @note the recommended way to set the to position for graphical
# objects is directly thru the object
# @see Char#end_at
- def end_at(x, y)
- set_marker_coords(x, y, to)
+ def end_at(x, y=nil)
+ to.coord x, y
end
# Creates a graphic frame and chart object associated with this anchor
# @return [Chart]
def add_chart(chart_type, options)
@@ -83,30 +86,7 @@
str << '</xdr:to>'
object.to_xml_string(str)
str << '<xdr:clientData/>'
str << '</xdr:twoCellAnchor>'
end
- private
-
- # parses coordinates and sets up a marker's row/col propery
- def set_marker_coords(x, y, marker)
- marker.col, marker.row = *parse_coord_args(x, y)
- end
-
- # handles multiple inputs for setting the position of a marker
- # @see Chart#start_at
- def parse_coord_args(x, y=0)
- if x.is_a?(String)
- x, y = *Axlsx::name_to_indices(x)
- end
- if x.is_a?(Cell)
- x, y = *x.pos
- end
- if x.is_a?(Array)
- x, y = *x
- end
- [x, y]
- end
-
-
end
end