Class: UnitsDB::Dimension
- Inherits:
-
Object
- Object
- UnitsDB::Dimension
- Defined in:
- lib/unitsdb_ruby/unitsdb.rb
Instance Attribute Summary collapse
-
#amount_of_substance ⇒ Object
readonly
Returns the value of attribute amount_of_substance.
-
#dimensionless ⇒ Object
readonly
Returns the value of attribute dimensionless.
-
#electric_current ⇒ Object
readonly
Returns the value of attribute electric_current.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#luminous_intensity ⇒ Object
readonly
Returns the value of attribute luminous_intensity.
-
#mass ⇒ Object
readonly
Returns the value of attribute mass.
-
#plane_angle ⇒ Object
readonly
Returns the value of attribute plane_angle.
-
#thermodynamic_temperature ⇒ Object
readonly
Returns the value of attribute thermodynamic_temperature.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #exponent(key) ⇒ Object
-
#initialize(id, hash) ⇒ Dimension
constructor
A new instance of Dimension.
- #keys ⇒ Object
- #vector ⇒ Object
Constructor Details
#initialize(id, hash) ⇒ Dimension
Returns a new instance of Dimension.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 6 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[: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 rescue raise StandardError.new "Parse fail on Dimension #{id}: #{hash}" end end |
Instance Attribute Details
#amount_of_substance ⇒ Object (readonly)
Returns the value of attribute amount_of_substance.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def amount_of_substance @amount_of_substance end |
#dimensionless ⇒ Object (readonly)
Returns the value of attribute dimensionless.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def dimensionless @dimensionless end |
#electric_current ⇒ Object (readonly)
Returns the value of attribute electric_current.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def electric_current @electric_current end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def id @id end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def length @length end |
#luminous_intensity ⇒ Object (readonly)
Returns the value of attribute luminous_intensity.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def luminous_intensity @luminous_intensity end |
#mass ⇒ Object (readonly)
Returns the value of attribute mass.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def mass @mass end |
#plane_angle ⇒ Object (readonly)
Returns the value of attribute plane_angle.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def plane_angle @plane_angle end |
#thermodynamic_temperature ⇒ Object (readonly)
Returns the value of attribute thermodynamic_temperature.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def thermodynamic_temperature @thermodynamic_temperature end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
3 4 5 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3 def time @time end |
Instance Method Details
#exponent(key) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 37 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 |
#keys ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 24 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 |
#vector ⇒ Object
50 51 52 53 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 50 def vector "#{@length}:#{@mass}:#{@time}:#{@electric_current}:#{@thermodynamic_temperature}:#{@amount_of_substance}:"\ "#{@luminous_intensity}:#{@plane_angle}" end |