Class: Unit::Parser
- Inherits:
-
Object
- Object
- Unit::Parser
- Defined in:
- lib/unitmanager/unit_composition.rb
Instance Method Summary collapse
-
#initialize(units) ⇒ Parser
constructor
A new instance of Parser.
- #parse_operand_symbols(string) ⇒ Object
- #to_units(unit_spec) ⇒ Object
Constructor Details
#initialize(units) ⇒ Parser
Returns a new instance of Parser.
153 154 155 |
# File 'lib/unitmanager/unit_composition.rb', line 153 def initialize(units) @units = units end |
Instance Method Details
#parse_operand_symbols(string) ⇒ Object
168 169 170 171 |
# File 'lib/unitmanager/unit_composition.rb', line 168 def parse_operand_symbols(string) operands = string.nil? ? [] : string.split(/\*/) operands.collect{|name| name.to_sym} end |
#to_units(unit_spec) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/unitmanager/unit_composition.rb', line 157 def to_units(unit_spec) operands = unit_spec.split(/\//) raise "Invalid Number of Operands in : #{unit_spec}" if operands.size > 2 { :dividends => @units.collect_for(parse_operand_symbols(operands[0])), :divisors => @units.collect_for(parse_operand_symbols(operands[1])) } end |