module Unitwise

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

Constants

VERSION

Public Class Methods

data_file(key) click to toggle source

A helper to get the location of a yaml data file @api private

# File lib/unitwise.rb, line 68
def self.data_file(key)
  File.join path, 'data', "#{key}.yaml"
end
path() click to toggle source

The system path for the installed gem @api private

# File lib/unitwise.rb, line 62
def self.path
  @path ||= File.dirname(File.dirname(__FILE__))
end
register(atom_hash) click to toggle source

Add additional atoms. Useful for registering uncommon or custom units. @param properties [Hash] Properties of the atom @return [Unitwise::Atom] The newly created atom @raise [Unitwise::DefinitionError]

# 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
valid?(expression) click to toggle source

Determine if a given string is a valid unit expression @param expression [String] @return [true, false] @api public

# File lib/unitwise.rb, line 40
def self.valid?(expression)
  begin
    !!Unitwise::Expression.decompose(expression)
  rescue ExpressionError
    false
  end
end