Class: OoxmlParser::OoxmlSize
- Inherits:
-
Object
- Object
- OoxmlParser::OoxmlSize
- Defined in:
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb
Overview
Size of some object
Instance Attribute Summary collapse
-
#unit ⇒ Symbol
Units of measurement.
-
#value ⇒ Float
Value of size.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value = 0, unit = :dxa) ⇒ OoxmlSize
constructor
A new instance of OoxmlSize.
-
#parse(node) ⇒ OoxmlSize
Parse OoxmlSize.
-
#to_base_unit ⇒ OoxmlSize
Convert all values to one same base unit.
- #to_s ⇒ Object
-
#to_unit(output_unit) ⇒ OoxmlSize
Converted unit.
- #zero? ⇒ Boolean
Constructor Details
#initialize(value = 0, unit = :dxa) ⇒ OoxmlSize
Returns a new instance of OoxmlSize.
9 10 11 12 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 9 def initialize(value = 0, unit = :dxa) @unit = unit @value = value end |
Instance Attribute Details
#unit ⇒ Symbol
Returns units of measurement.
7 8 9 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 7 def unit @unit end |
#value ⇒ Float
Returns value of size.
5 6 7 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 5 def value @value end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 29 def ==(other) (to_base_unit.value - other.to_base_unit.value).abs < 10**(OoxmlParser.configuration.accuracy + 2) end |
#parse(node) ⇒ OoxmlSize
Parse OoxmlSize
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 17 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 ⇒ OoxmlSize
Convert all values to one same base unit
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 43 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 return 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) else self end end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 37 def to_s "#{@value} #{@unit}" end |
#to_unit(output_unit) ⇒ OoxmlSize
Returns converted unit.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 76 def to_unit(output_unit) base_unit = to_base_unit case output_unit when :centimeter return OoxmlSize.new((base_unit.value / 360_000).round(OoxmlParser.configuration.accuracy), output_unit) when :point return OoxmlSize.new((base_unit.value / 12_700).round(OoxmlParser.configuration.accuracy), output_unit) when :half_point return OoxmlSize.new((base_unit.value / (12_700 * 2)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_eighth_point return OoxmlSize.new((base_unit.value / (12_700 * 8)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_100th_point return OoxmlSize.new((base_unit.value / (12_700 / 100)).round(OoxmlParser.configuration.accuracy), output_unit) when :one_240th_cm return OoxmlSize.new((base_unit.value / 1500).round(OoxmlParser.configuration.accuracy), output_unit) when :dxa, :twip return OoxmlSize.new((base_unit.value / 635).round(OoxmlParser.configuration.accuracy), output_unit) when :inch return OoxmlSize.new((base_unit.value / 914_400).round(OoxmlParser.configuration.accuracy), output_unit) when :percent return OoxmlSize.new((base_unit.value / 50).round(OoxmlParser.configuration.accuracy), output_unit) when :spacing_point return OoxmlSize.new((base_unit.value / (12_700 * 100)).round(OoxmlParser.configuration.accuracy), output_unit) else return base_unit end end |
#zero? ⇒ Boolean
33 34 35 |
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb', line 33 def zero? @value.zero? end |