Class: Unitsml::Dimension
- Inherits:
-
Object
- Object
- Unitsml::Dimension
- Defined in:
- lib/unitsml/dimension.rb
Instance Attribute Summary collapse
-
#dimension_name ⇒ Object
Returns the value of attribute dimension_name.
-
#power_numerator ⇒ Object
Returns the value of attribute power_numerator.
Instance Method Summary collapse
- #==(object) ⇒ Object
- #dim_hash ⇒ Object
- #dim_symbols ⇒ Object
- #generate_id ⇒ Object
-
#initialize(dimension_name, power_numerator = nil) ⇒ Dimension
constructor
A new instance of Dimension.
- #modelize(value) ⇒ Object
- #to_asciimath ⇒ Object
- #to_html ⇒ Object
- #to_latex ⇒ Object
- #to_mathml ⇒ Object
- #to_unicode ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(dimension_name, power_numerator = nil) ⇒ Dimension
Returns a new instance of Dimension.
7 8 9 10 |
# File 'lib/unitsml/dimension.rb', line 7 def initialize(dimension_name, power_numerator = nil) @dimension_name = dimension_name @power_numerator = power_numerator end |
Instance Attribute Details
#dimension_name ⇒ Object
Returns the value of attribute dimension_name.
5 6 7 |
# File 'lib/unitsml/dimension.rb', line 5 def dimension_name @dimension_name end |
#power_numerator ⇒ Object
Returns the value of attribute power_numerator.
5 6 7 |
# File 'lib/unitsml/dimension.rb', line 5 def power_numerator @power_numerator end |
Instance Method Details
#==(object) ⇒ Object
12 13 14 15 16 |
# File 'lib/unitsml/dimension.rb', line 12 def ==(object) self.class == object.class && dimension_name == object&.dimension_name && power_numerator == object&.power_numerator end |
#dim_hash ⇒ Object
18 19 20 |
# File 'lib/unitsml/dimension.rb', line 18 def dim_hash Unitsdb.parsable_dimensions[dimension_name] end |
#dim_symbols ⇒ Object
22 23 24 |
# File 'lib/unitsml/dimension.rb', line 22 def dim_symbols dim_hash&.values&.last&.values&.first["dim_symbols"].first end |
#generate_id ⇒ Object
68 69 70 |
# File 'lib/unitsml/dimension.rb', line 68 def generate_id "#{dimension_name.split('_').last}#{power_numerator}" end |
#modelize(value) ⇒ Object
81 82 83 |
# File 'lib/unitsml/dimension.rb', line 81 def modelize(value) value&.split("_")&.map(&:capitalize)&.join end |
#to_asciimath ⇒ Object
50 51 52 53 54 |
# File 'lib/unitsml/dimension.rb', line 50 def to_asciimath value = dim_symbols["ascii"] value = "#{value}^#{power_numerator}" if power_numerator value end |
#to_html ⇒ Object
56 57 58 59 60 |
# File 'lib/unitsml/dimension.rb', line 56 def to_html value = dim_symbols["html"] value = "#{value}<sup>#{power_numerator}</sup>" if power_numerator value end |
#to_latex ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/unitsml/dimension.rb', line 42 def to_latex value = dim_symbols["latex"] if power_numerator value = "#{value}^#{power_numerator}" end value end |
#to_mathml ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/unitsml/dimension.rb', line 26 def to_mathml value = dim_symbols["mathml"] value = Ox.parse(value) if power_numerator msup = Utility.ox_element("msup") msup << (Utility.ox_element("mrow") << value) msup << ( Utility.ox_element("mrow") << ( Utility.ox_element("mn") << power_numerator ) ) value = msup end value end |
#to_unicode ⇒ Object
62 63 64 65 66 |
# File 'lib/unitsml/dimension.rb', line 62 def to_unicode value = dim_symbols["unicode"] value = "#{value}^#{power_numerator}" if power_numerator value end |
#to_xml ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/unitsml/dimension.rb', line 72 def to_xml fields = dim_hash[:fields] symbol = fields.values.first["symbol"] power_numerator_value = power_numerator || 1 attributes = { symbol: symbol, powerNumerator: power_numerator_value } element_name = modelize(fields.keys.first.capitalize) Utility.ox_element(element_name, attributes: attributes) end |