Class: OoxmlParser::OOXMLCoordinates

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

Overview

Docx Coordinates

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(x_value = nil, y_value = nil, parent: nil) ⇒ OOXMLCoordinates

Returns a new instance of OOXMLCoordinates.



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

def initialize(x_value = nil, y_value = nil, parent: nil)
  @x = if x_value.is_a?(OoxmlSize)
         x_value
       else
         OoxmlSize.new(x_value)
       end
  @y = if y_value.is_a?(OoxmlSize)
         y_value
       else
         OoxmlSize.new(y_value)
       end
  super(parent: parent)
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#==(other) ⇒ True, False

Compare two OOXMLCoordinates objects

Parameters:

Returns:

  • (True, False)

    result of comparison



30
31
32
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 30

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

#parse(node, x_attr: 'x', y_attr: 'y', unit: :dxa) ⇒ OOXMLCoordinates

Parse OOXMLCoordinates object

Parameters:

  • 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:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 40

def parse(node, x_attr: 'x', y_attr: 'y', unit: :dxa)
  node.attributes.each do |key, value|
    case key
    when x_attr
      @x = OoxmlSize.new(value.value.to_f, unit)
    when y_attr
      @y = OoxmlSize.new(value.value.to_f, unit)
    end
  end
  self
end

#to_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



23
24
25
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb', line 23

def to_s
  "(#{@x}; #{@y})"
end