class OoxmlParser::OoxmlSize
Size
of some object
Attributes
unit[RW]
@return [Symbol] units of measurement
value[RW]
@return [Float] value of size
Public Class Methods
new(value = 0, unit = :dxa)
click to toggle source
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 11 def initialize(value = 0, unit = :dxa) @unit = unit @value = value end
Public Instance Methods
==(other)
click to toggle source
Compare this object to other @param other [Object] any other object @return [True, False] result of comparision
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 34 def ==(other) (to_base_unit.value - other.to_base_unit.value).abs < 10**(OoxmlParser.configuration.accuracy + 2) end
parse(node)
click to toggle source
Parse OoxmlSize
@param [Nokogiri::XML:Node] node with OoxmlSize
@return [OoxmlSize] result of parsing
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 19 def parse(node) node.attributes.each do |key, value| case key when 'type' @unit = value.value.to_sym when 'w', 'val' @value = value.value.to_f end end self end
to_base_unit()
click to toggle source
Convert all values to one same base unit @return [OoxmlSize] base unit
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 51 def to_base_unit case @unit when :centimeter OoxmlSize.new(@value * 360_000) when :point OoxmlSize.new(@value * 12_700) when :half_point OoxmlSize.new(@value * (12_700 / 2)) when :one_eighth_point OoxmlSize.new(@value * (12_700 / 8)) when :one_100th_point OoxmlSize.new(@value * (12_700 / 100)) when :one_240th_cm OoxmlSize.new(@value * 1500) when :dxa, :twip OoxmlSize.new(@value * 635, :emu) when :inch OoxmlSize.new(@value * 914_400, :emu) when :spacing_point OoxmlSize.new(@value * (12_700 / 100), :emu) when :percent OoxmlSize.new(@value * 100_000, :one_100000th_percent) when :pct OoxmlSize.new(@value * 100_000 / 50, :one_100000th_percent) when :one_1000th_percent OoxmlSize.new(@value * 100, :one_100000th_percent) when :one_60000th_degree OoxmlSize.new(@value, :one_60000th_degree) when :degree OoxmlSize.new(@value * 60_000, :one_60000th_degree) else self end end
to_s(unit = :centimeter)
click to toggle source
@param unit [Symbol] unit in which output should be @return [String] string representation of size
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 44 def to_s(unit = :centimeter) converted = to_unit(unit) "#{converted.value.to_f} #{converted.unit}" end
to_unit(output_unit)
click to toggle source
@param output_unit [Symbol] output unit of convertion @return [OoxmlSize] converted unit
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 88 def to_unit(output_unit) base_unit = to_base_unit case output_unit when :centimeter OoxmlSize.new((base_unit.value / 360_000).round(OoxmlParser.configuration.accuracy), output_unit) when :point OoxmlSize.new((base_unit.value / 12_700).round(OoxmlParser.configuration.accuracy), output_unit) when :half_point OoxmlSize.new((base_unit.value / (12_700 * 2)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_eighth_point OoxmlSize.new((base_unit.value / (12_700 * 8)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_100th_point OoxmlSize.new((base_unit.value / (12_700 / 100)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_240th_cm OoxmlSize.new((base_unit.value / 1500).round(OoxmlParser.configuration.accuracy), output_unit) when :dxa, :twip OoxmlSize.new((base_unit.value / 635).round(OoxmlParser.configuration.accuracy), output_unit) when :inch OoxmlSize.new((base_unit.value / 914_400).round(OoxmlParser.configuration.accuracy), output_unit) when :percent OoxmlSize.new((base_unit.value / 50).round(OoxmlParser.configuration.accuracy), output_unit) when :spacing_point OoxmlSize.new((base_unit.value / (12_700 * 100)).round(OoxmlParser.configuration.accuracy), output_unit) else base_unit end end
zero?()
click to toggle source
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb, line 38 def zero? @value.zero? end