Class: UnitsDB::Unit
- Inherits:
-
Object
- Object
- UnitsDB::Unit
- 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.
-
#prefixed ⇒ Object
readonly
Returns the value of attribute prefixed.
-
#quantities ⇒ Object
readonly
Returns the value of attribute quantities.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#root_units ⇒ Object
readonly
Returns the value of attribute root_units.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#si_derived_bases ⇒ Object
readonly
Returns the value of attribute si_derived_bases.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
-
#symbols_hash ⇒ Object
readonly
Returns the value of attribute symbols_hash.
-
#unit_system ⇒ Object
readonly
Returns the value of attribute unit_system.
Instance Method Summary collapse
-
#initialize(id, hash) ⇒ Unit
constructor
A new instance of Unit.
- #name ⇒ Object
- #symbolid ⇒ Object
- #symbolids ⇒ Object
- #system_name ⇒ Object
- #system_type ⇒ Object
Constructor Details
#initialize(id, hash) ⇒ Unit
Returns a new instance of Unit.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 124 def initialize(id, hash) begin @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 raise StandardError.new "Parse fail on Unit #{id}: #{hash}" end end |
Instance Attribute Details
#dimension ⇒ Object (readonly)
Returns the value of attribute dimension.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def dimension @dimension end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def id @id end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def names @names end |
#prefixed ⇒ Object (readonly)
Returns the value of attribute prefixed.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def prefixed @prefixed end |
#quantities ⇒ Object (readonly)
Returns the value of attribute quantities.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def quantities @quantities end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def root @root end |
#root_units ⇒ Object (readonly)
Returns the value of attribute root_units.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def root_units @root_units end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def short @short end |
#si_derived_bases ⇒ Object (readonly)
Returns the value of attribute si_derived_bases.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def si_derived_bases @si_derived_bases end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def symbols @symbols end |
#symbols_hash ⇒ Object (readonly)
Returns the value of attribute symbols_hash.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def symbols_hash @symbols_hash end |
#unit_system ⇒ Object (readonly)
Returns the value of attribute unit_system.
121 122 123 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 121 def unit_system @unit_system end |
Instance Method Details
#name ⇒ Object
152 153 154 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 152 def name @names.first end |
#symbolid ⇒ Object
156 157 158 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 156 def symbolid @symbols ? @symbols.first[:id] : @short end |
#symbolids ⇒ Object
160 161 162 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 160 def symbolids @symbols ? @symbols.map { |s| s[:id] } : [ @short ] end |
#system_name ⇒ Object
144 145 146 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 144 def system_name @unit_system[:name] end |
#system_type ⇒ Object
148 149 150 |
# File 'lib/unitsdb_ruby/unitsdb.rb', line 148 def system_type @unit_system[:type] end |