Class: UnitsDB::Dimension

Inherits:
Object
  • Object
show all
Defined in:
lib/unitsdb_ruby/unitsdb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_substanceObject (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

#dimensionlessObject (readonly)

Returns the value of attribute dimensionless.



3
4
5
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3

def dimensionless
  @dimensionless
end

#electric_currentObject (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

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3

def id
  @id
end

#lengthObject (readonly)

Returns the value of attribute length.



3
4
5
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3

def length
  @length
end

#luminous_intensityObject (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

#massObject (readonly)

Returns the value of attribute mass.



3
4
5
# File 'lib/unitsdb_ruby/unitsdb.rb', line 3

def mass
  @mass
end

#plane_angleObject (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_temperatureObject (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

#timeObject (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

#keysObject



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

#vectorObject



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