Class: Valuevaluevalue::Mass
- Inherits:
-
Object
- Object
- Valuevaluevalue::Mass
- Defined in:
- lib/valuevaluevalue/mass.rb
Constant Summary collapse
- UNITS =
[ MassUnit.new('Atomic Mass Unit', 'amu', 1.6605402e-27), MassUnit.new('Carat', 'ct', 0.0002), MassUnit.new('Cental', 'cwt', 45.359237), MassUnit.new('Centigram', 'cg', 0.00001), MassUnit.new('Decagram', 'dkg', 0.01), MassUnit.new('Dram', 'dr', 0.001771845195312), MassUnit.new('Grain', 'gr', 0.00006479891), MassUnit.new('Gram', 'g', 0.001), MassUnit.new('Hundredweight', 'hwt', 50.80234544), MassUnit.new('Kilogram', 'kg', 1), MassUnit.new('Long Ton', 'lton', 1016.0469088), MassUnit.new('Microgram', 'mcg', 1E-9), MassUnit.new('Milligram', 'mg', 0.000001), MassUnit.new('Ounce', 'oz', 0.028349523125), MassUnit.new('Pennyweight', 'dwt', 0.00155517384), MassUnit.new('Pound', 'lbs', 0.45359237), MassUnit.new('Quarter', 'qt', 12.70058636), MassUnit.new('Short Ton', 'ton', 907.18474), MassUnit.new('Stone', 'st', 6.35029318), MassUnit.new('Tonne', 't', 1000), MassUnit.new('Troy Ounce', 'troz', 0.0311034768) ].freeze
Instance Attribute Summary collapse
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #convert_to(unit) ⇒ Object
-
#initialize(value, unit) ⇒ Mass
constructor
A new instance of Mass.
Constructor Details
#initialize(value, unit) ⇒ Mass
Returns a new instance of Mass.
31 32 33 34 35 |
# File 'lib/valuevaluevalue/mass.rb', line 31 def initialize(value, unit) unit_exists?(unit) @value = value @unit = unit end |
Instance Attribute Details
#unit ⇒ Object
Returns the value of attribute unit.
5 6 7 |
# File 'lib/valuevaluevalue/mass.rb', line 5 def unit @unit end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/valuevaluevalue/mass.rb', line 5 def value @value end |
Instance Method Details
#convert_to(unit) ⇒ Object
37 38 39 40 |
# File 'lib/valuevaluevalue/mass.rb', line 37 def convert_to(unit) unit_exists?(unit) convert_to_kg / find_unit(unit).mass_in_kg end |