Class: Alchemist::PrefixParser

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemist/prefix_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(unit) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/alchemist/prefix_parser.rb', line 3

def parse(unit)
  matches = unit.to_s.match(prefix_matcher)
  prefix, parsed_unit = matches.captures

  if prefix && library.si_units.include?(parsed_unit)
    value = prefixed_value_for(prefix.to_sym, parsed_unit)
    [value, parsed_unit.to_sym]
  else
    [1, unit]
  end
end

#prefix_matcherObject



15
16
17
# File 'lib/alchemist/prefix_parser.rb', line 15

def prefix_matcher
  @prefix_matcher ||= generate_prefix_matcher
end