Sha256: 0eb63119f45045d739310bb9c046d198b5a23f1cd4fa60abc932dfd30429f307

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# Docx Coordinates
module OoxmlParser
  class OOXMLCoordinates
    attr_accessor :x, :y

    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

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

    # Compare two OOXMLCoordinates objects
    # @param other [OOXMLCoordinates] other object
    # @return [True, False] result of comparasion
    def ==(other)
      x == other.x && y == other.y
    end

    # Parse OOXMLCoordinates object
    # @param position_node [Nokogiri::XML:Element] node to parse
    # @param x_attr [String] name of x attribute
    # @param y_attr [String] name of y attribute
    # @param unit [Symbol] unit in which data is stored
    # @return [OOXMLCoordinates] result of parsing
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ooxml_parser-0.4.1 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb
ooxml_parser-0.4.0 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb
ooxml_parser-0.3.0 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb
ooxml_parser-0.2.0 lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb