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
-
.compose(terms, method = :primary_code) ⇒ String
Build a string representation of a collection of terms.
-
.decompose(expression) ⇒ Array
Convert a string representation of a unit, and turn it into a an array of terms.
Class Method Details
.compose(terms, method = :primary_code) ⇒ String
Build a string representation of a collection of terms
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, and turn it into a an array of terms
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/unitwise/expression.rb', line 30 def decompose(expression) expression = expression.to_s if decomposed.key?(expression) decomposed[expression] else decomposed[expression] = begin Decomposer.new(expression).terms rescue ExpressionError nil end end end |