Class: UnitsDB::Quantity
- Inherits:
-
Object
- Object
- UnitsDB::Quantity
- Defined in:
- lib/unitsdb_ruby/unitsdb.rb
Instance Attribute Summary collapse
-
#dimension ⇒ Object
readonly
Returns the value of attribute dimension.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
-
#initialize(id, hash) ⇒ Quantity
constructor
A new instance of Quantity.
- #name ⇒ Object
- #unit ⇒ Object
Constructor Details
#initialize(id, hash) ⇒ Quantity
Returns a new instance of Quantity.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 99 def initialize(id, hash) 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(/^#/, "") } rescue raise StandardError.new "Parse fail on Quantity #{id}: #{hash}" end end |
Instance Attribute Details
#dimension ⇒ Object (readonly)
Returns the value of attribute dimension.
97 98 99 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97 def dimension @dimension end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
97 98 99 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97 def id @id end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
97 98 99 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97 def names @names end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
97 98 99 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97 def type @type end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
97 98 99 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97 def units @units end |
Instance Method Details
#name ⇒ Object
111 112 113 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 111 def name @names&.first end |
#unit ⇒ Object
115 116 117 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 115 def unit @units&.first end |