Module: Unitsml::Unitsdb
- Defined in:
- lib/unitsml/unitsdb.rb,
lib/unitsml/unitsdb/units.rb,
lib/unitsml/unitsdb/prefixes.rb,
lib/unitsml/unitsdb/dimension.rb,
lib/unitsml/unitsdb/dimensions.rb,
lib/unitsml/unitsdb/quantities.rb,
lib/unitsml/unitsdb/dimension_quantity.rb
Defined Under Namespace
Classes: Dimension, DimensionQuantity, Dimensions, Prefixes, Quantities, Units
Class Method Summary
collapse
Class Method Details
.dimensions ⇒ Object
19
20
21
|
# File 'lib/unitsml/unitsdb.rb', line 19
def dimensions
@@dim_file ||= ::Unitsdb::Dimensions.from_yaml(load_file(:dimensions))
end
|
.load_file(file_name) ⇒ Object
6
7
8
9
|
# File 'lib/unitsml/unitsdb.rb', line 6
def load_file(file_name)
@@hash ||= {}
@@hash[file_name] ||= File.read(valid_path(file_name))
end
|
.prefixes ⇒ Object
15
16
17
|
# File 'lib/unitsml/unitsdb.rb', line 15
def prefixes
@@prefixes ||= ::Unitsdb::Prefixes.from_yaml(load_file(:prefixes))
end
|
.prefixes_array ⇒ Object
27
28
29
|
# File 'lib/unitsml/unitsdb.rb', line 27
def prefixes_array
@@prefixes_array ||= prefixes.ascii_symbols.sort_by(&:length)
end
|
.prefixes_by_size(size) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/unitsml/unitsdb.rb', line 31
def prefixes_by_size(size)
@@sized_prefixes ||= {}
return @@sized_prefixes[size] if @@sized_prefixes.key?(size)
@@sized_prefixes[size] = prefixes_array.select { |p| p.size == size }
end
|
.quantities ⇒ Object
23
24
25
|
# File 'lib/unitsml/unitsdb.rb', line 23
def quantities
@@quantities ||= ::Unitsdb::Quantities.from_yaml(load_file(:quantities))
end
|
.units ⇒ Object
11
12
13
|
# File 'lib/unitsml/unitsdb.rb', line 11
def units
@@units_file ||= ::Unitsdb::Units.from_yaml(load_file(:units))
end
|
.valid_path(file_name) ⇒ Object
38
39
40
41
42
|
# File 'lib/unitsml/unitsdb.rb', line 38
def valid_path(file_name)
File.expand_path(
File.join(__dir__, "..", "..","unitsdb", "#{file_name}.yaml")
)
end
|