class UnitsDB::Dimension
Attributes
amount_of_substance[R]
dimensionless[R]
electric_current[R]
id[R]
length[R]
luminous_intensity[R]
mass[R]
name[R]
plane_angle[R]
symbols[R]
symbols_hash[R]
thermodynamic_temperature[R]
time[R]
Public Class Methods
new(id, hash)
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 9 def initialize(id, hash) @id = id @dimensionless = hash[:dimensionless] init_dimension(hash) name_dimension(hash) rescue StandardError raise StandardError.new "Parse fail on Dimension #{id}: #{hash}" end
Public Instance Methods
exponent(key)
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 62 def exponent(key) case key when "Length" then @length when "Mass" then @mass when "Time" then @time when "ElectricCurrent" then @electric_current when "ThermodynamicTemperature" then @thermodynamic_temperature when "AmountOfSubstance" then @amount_of_substance when "LuminousIntensity" then @luminous_intensity when "PlaneAngle" then @plane_angle end end
init_dimension(hash)
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 18 def init_dimension(hash) 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[: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 end
keys()
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 49 def keys ret = [] @length and ret << "Length" @mass and ret << "Mass" @time and ret << "Time" @electric_current and ret << "ElectricCurrent" @thermodynamic_temperature and ret << "ThermodynamicTemperature" @amount_of_substance and ret << "AmountOfSubstance" @luminous_intensity and ret << "LuminousIntensity" @plane_angle and ret << "PlaneAngle" ret end
name_dimension(hash)
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 34 def name_dimension(hash) acc = %i(length mass time electric_current thermodynamic_temperature amount_of_substance luminous_intensity plane_angle) .each_with_object({}) do |x, m| hash[x] and m[x] = hash[x][:powerNumerator] end return unless acc.keys.size == 1 && acc.values[0] == 1 dim = acc.keys[0] @name = dim.to_s @symbols = hash[dim][:dim_symbols] @symbols_hash = @symbols&.each_with_object({}) { |h, m| m[h[:id]] = h } || {} end
symbolid()
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 81 def symbolid @symbols ? @symbols.first[:id] : nil end
symbolids()
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 85 def symbolids @symbols ? @symbols.map { |s| s[:id] } : [] end
vector()
click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 75 def vector "#{@length}:#{@mass}:#{@time}:#{@electric_current}:"\ "#{@thermodynamic_temperature}:#{@amount_of_substance}:"\ "#{@luminous_intensity}:#{@plane_angle}" end