Module: Unitwise

Defined in:
lib/unitwise.rb,
lib/unitwise/atom.rb,
lib/unitwise/base.rb,
lib/unitwise/term.rb,
lib/unitwise/unit.rb,
lib/unitwise/scale.rb,
lib/unitwise/errors.rb,
lib/unitwise/number.rb,
lib/unitwise/prefix.rb,
lib/unitwise/search.rb,
lib/unitwise/version.rb,
lib/unitwise/standard.rb,
lib/unitwise/compatible.rb,
lib/unitwise/expression.rb,
lib/unitwise/functional.rb,
lib/unitwise/measurement.rb,
lib/unitwise/expression/parser.rb,
lib/unitwise/expression/matcher.rb,
lib/unitwise/expression/composer.rb,
lib/unitwise/expression/decomposer.rb,
lib/unitwise/expression/transformer.rb

Overview

Unitwise is a library for performing mathematical operations and conversions on all units defined by the [Unified Code for Units of Measure(UCUM).

Defined Under Namespace

Modules: Compatible, Expression, Search, Standard Classes: Atom, Base, ConversionError, DefinitionError, ExpressionError, Functional, Measurement, Number, Prefix, Scale, Term, Unit

Constant Summary

VERSION =
'2.2.0'.freeze

Class Method Summary collapse

Class Method Details

.data_file(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A helper to get the location of a yaml data file



68
69
70
# File 'lib/unitwise.rb', line 68

def self.data_file(key)
  File.join path, 'data', "#{key}.yaml"
end

.pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The system path for the installed gem



62
63
64
# File 'lib/unitwise.rb', line 62

def self.path
  @path ||= File.dirname(File.dirname(__FILE__))
end

.register(atom_hash) ⇒ Unitwise::Atom

Add additional atoms. Useful for registering uncommon or custom units.



52
53
54
55
56
57
58
# File 'lib/unitwise.rb', line 52

def self.register(atom_hash)
  atom = Unitwise::Atom.new(atom_hash)
  atom.validate!
  Unitwise::Atom.all.push(atom)
  Unitwise::Expression::Decomposer.send(:reset)
  atom
end

.search(term) ⇒ Array

Search for available compounds. This is just a helper method for convenience



32
33
34
# File 'lib/unitwise.rb', line 32

def self.search(term)
  Search.search(term)
end

.valid?(expression) ⇒ true, false

Determine if a given string is a valid unit expression



40
41
42
43
44
45
46
# File 'lib/unitwise.rb', line 40

def self.valid?(expression)
  begin
    !!Unitwise::Expression.decompose(expression)
  rescue ExpressionError
    false
  end
end