Class: OoxmlParser::OOXMLCoordinates

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ OOXMLCoordinates

Returns a new instance of OOXMLCoordinates.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 6

def initialize(x, y)
  @x = if x.is_a?(OoxmlSize)
         x
       else
         OoxmlSize.new(x)
       end
  @y = if y.is_a?(OoxmlSize)
         y
       else
         OoxmlSize.new(y)
       end
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 4

def y
  @y
end

Class Method Details

.parse(position_node, x_attr: 'x', y_attr: 'y', unit: :dxa) ⇒ OOXMLCoordinates

Parse OOXMLCoordinates object

Parameters:

  • position_node (Nokogiri::XML:Element)

    node to parse

  • x_attr (String) (defaults to: 'x')

    name of x attribute

  • y_attr (String) (defaults to: 'y')

    name of y attribute

  • unit (Symbol) (defaults to: :dxa)

    unit in which data is stored

Returns:



36
37
38
39
40
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 36

def self.parse(position_node, x_attr: 'x', y_attr: 'y', unit: :dxa)
  return if position_node.attribute(x_attr).nil? || position_node.attribute(y_attr).nil?
  OOXMLCoordinates.new(OoxmlSize.new(position_node.attribute(x_attr).value.to_f, unit),
                       OoxmlSize.new(position_node.attribute(y_attr).value.to_f, unit))
end

Instance Method Details

#==(other) ⇒ True, False

Compare two OOXMLCoordinates objects

Parameters:

Returns:

  • (True, False)

    result of comparasion



26
27
28
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 26

def ==(other)
  x == other.x && y == other.y
end

#to_sObject



19
20
21
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 19

def to_s
  '(' + @x.to_s + '; ' + @y.to_s + ')'
end