lib/unitsdb_ruby/unitsdb.rb in asciimath2unitsml-0.3.2 vs lib/unitsdb_ruby/unitsdb.rb in asciimath2unitsml-0.3.3

- old
+ new

@@ -1,23 +1,28 @@ module UnitsDB class Dimension - attr_reader :id, :length, :mass, :time, :electric_current, :thermodynamic_temperature, + attr_reader :id, :length, :mass, :time, :electric_current, + :thermodynamic_temperature, :amount_of_substance, :luminous_intensity, :plane_angle, :dimensionless def initialize(id, hash) begin @id = id @dimensionless = hash[:dimensionless] hash[:length] and @length = hash[:length][:powerNumerator].to_i hash[:mass] and @mass = hash[:mass][:powerNumerator].to_i hash[:time] and @time = hash[:time][:powerNumerator].to_i - hash[:electric_current] and @electric_current = hash[:electric_current][:powerNumerator].to_i + hash[:electric_current] and + @electric_current = hash[:electric_current][:powerNumerator].to_i hash[:thermodynamic_temperature] and @thermodynamic_temperature = hash[:thermodynamic_temperature][:powerNumerator].to_i - hash[:amount_of_substance] and @amount_of_substance = hash[:amount_of_substance][:powerNumerator].to_i - hash[:luminous_intensity] and @luminous_intensity = hash[:luminous_intensity][:powerNumerator].to_i - hash[:plane_angle] and @plane_angle = hash[:plane_angle][:powerNumerator].to_i + hash[:amount_of_substance] and + @amount_of_substance = hash[:amount_of_substance][:powerNumerator].to_i + hash[:luminous_intensity] and + @luminous_intensity = hash[:luminous_intensity][:powerNumerator].to_i + hash[:plane_angle] and + @plane_angle = hash[:plane_angle][:powerNumerator].to_i rescue raise StandardError.new "Parse fail on Dimension #{id}: #{hash}" end end @@ -46,11 +51,12 @@ when "PlaneAngle" then @plane_angle end end def vector - "#{@length}:#{@mass}:#{@time}:#{@electric_current}:#{@thermodynamic_temperature}:#{@amount_of_substance}:"\ + "#{@length}:#{@mass}:#{@time}:#{@electric_current}:"\ + "#{@thermodynamic_temperature}:#{@amount_of_substance}:"\ "#{@luminous_intensity}:#{@plane_angle}" end end class Prefix @@ -100,11 +106,12 @@ begin @id = id @dimension = hash[:dimension_url].sub(/^#/, "") @type = hash[:quantity_type] hash[:quantity_name] and @names = hash[:quantity_name] - hash[:unit_reference] and @units = hash[:unit_reference].map { |x| x[:url].sub(/^#/, "") } + hash[:unit_reference] and + @units = hash[:unit_reference].map { |x| x[:url].sub(/^#/, "") } rescue raise StandardError.new "Parse fail on Quantity #{id}: #{hash}" end end @@ -116,26 +123,29 @@ @units&.first end end class Unit - attr_reader :id, :dimension, :short, :root, :unit_system, :names, :symbols, :symbols_hash, :root_units, :quantities, + attr_reader :id, :dimension, :short, :root, :unit_system, :names, + :symbols, :symbols_hash, :root_units, :quantities, :si_derived_bases, :prefixed def initialize(id, hash) begin @id = id @short = short @dimension = hash[:dimension_url].sub(/^#/, "") hash[:short] && !hash[:short].empty? and @short = hash[:short] @unit_system = hash[:unit_system] @names = hash[:unit_name] - @symbols_hash = hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {} + @symbols_hash = + hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {} @symbols = hash[:unit_symbols] hash[:root_units] and hash[:root_units][:enumerated_root_units] and @root = hash[:root_units][:enumerated_root_units] - hash[:quantity_reference] and @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") } + hash[:quantity_reference] and + @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") } hash[:si_derived_bases] and @si_derived_bases = hash[:si_derived_bases] @prefixed = (hash[:prefixed] == true) rescue raise StandardError.new "Parse fail on Unit #{id}: #{hash}" end @@ -156,9 +166,9 @@ def symbolid @symbols ? @symbols.first[:id] : @short end def symbolids - @symbols ? @symbols.map { |s| s[:id] } : [ @short ] + @symbols ? @symbols.map { |s| s[:id] } : [@short] end end end