class UnitsDB::Unit

Attributes

dimension[R]
id[R]
names[R]
prefixed[R]
quantities[R]
root[R]
root_units[R]
short[R]
si_derived_bases[R]
symbols[R]
symbols_hash[R]
unit_system[R]

Public Class Methods

new(id, hash) click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 156
def initialize(id, hash)
  @id = id
  @short = short
  @dimension = hash[:dimension_url].sub(/^#/, "")
  hash[:short] && !hash[:short].empty? and @short = hash[:short]
  @unit_system = hash[:unit_system]
  @names = hash[:unit_name]
  @symbols_hash =
    hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {}
  @symbols = hash[:unit_symbols]
  hash[:root_units] and hash[:root_units][:enumerated_root_units] and
    @root = hash[:root_units][:enumerated_root_units]
  hash[:quantity_reference] and
    @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") }
  hash[:si_derived_bases] and @si_derived_bases = hash[:si_derived_bases]
  @prefixed = (hash[:prefixed] == true)
rescue StandardError
  raise StandardError.new "Parse fail on Unit #{id}: #{hash}"
end

Public Instance Methods

name() click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 184
def name
  @names.first
end
symbolid() click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 188
def symbolid
  @symbols ? @symbols.first[:id] : @short
end
symbolids() click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 192
def symbolids
  @symbols ? @symbols.map { |s| s[:id] } : [@short]
end
system_name() click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 176
def system_name
  @unit_system[:name]
end
system_type() click to toggle source
# File lib/unitsdb_ruby/unitsdb.rb, line 180
def system_type
  @unit_system[:type]
end