Module: Unitwise::Expression

Defined in:
lib/unitwise/expression.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

The Expression module encompases all functions around encoding and decoding strings into Measurement::Units and vice-versa.

Defined Under Namespace

Classes: Composer, Decomposer, Matcher, Parser, Transformer

Class Method Summary collapse

Class Method Details

.compose(terms, method = :primary_code) ⇒ String

Build a string representation of a collection of terms

Examples:

Unitwise::Expression.compose(terms) # => "m2/s2"

Parameters:

  • terms (Array)

Returns:

  • (String)


18
19
20
# File 'lib/unitwise/expression.rb', line 18

def compose(terms, method = :primary_code)
  Composer.new(terms, method).expression
end

.decompose(expression) ⇒ Array

Convert a string representation of a unit into an array of terms

Examples:

Unitwise::Expression.decompose("m2/s2")
# => [<Unitwise::Term m2>, <Unitwise::Term s-2>]

Parameters:

  • expression (String)

    The string you wish to convert

Returns:

  • (Array)


29
30
31
# File 'lib/unitwise/expression.rb', line 29

def decompose(expression)
  Decomposer.parse(expression)
end