Class: UnitsDB::Quantity

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) ⇒ 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

#dimensionObject (readonly)

Returns the value of attribute dimension.



97
98
99
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97

def dimension
  @dimension
end

#idObject (readonly)

Returns the value of attribute id.



97
98
99
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97

def id
  @id
end

#namesObject (readonly)

Returns the value of attribute names.



97
98
99
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97

def names
  @names
end

#typeObject (readonly)

Returns the value of attribute type.



97
98
99
# File 'lib/unitsdb_ruby/unitsdb.rb', line 97

def type
  @type
end

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

#nameObject



111
112
113
# File 'lib/unitsdb_ruby/unitsdb.rb', line 111

def name
  @names&.first
end

#unitObject



115
116
117
# File 'lib/unitsdb_ruby/unitsdb.rb', line 115

def unit
  @units&.first
end