Class: Alchemist::PrefixParser
- Inherits:
-
Object
- Object
- Alchemist::PrefixParser
- Defined in:
- lib/alchemist/prefix_parser.rb
Instance Attribute Summary collapse
-
#exponent ⇒ Object
readonly
Returns the value of attribute exponent.
-
#unit_name ⇒ Object
readonly
Returns the value of attribute unit_name.
Instance Method Summary collapse
- #guess_type(from) ⇒ Object
-
#initialize(unit) ⇒ PrefixParser
constructor
A new instance of PrefixParser.
- #prefix_matcher ⇒ Object
- #shares_type?(from) ⇒ Boolean
Constructor Details
#initialize(unit) ⇒ PrefixParser
Returns a new instance of PrefixParser.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/alchemist/prefix_parser.rb', line 5 def initialize(unit) @unit = unit matches = unit.to_s.match(prefix_matcher) prefix, parsed_unit = matches.captures if prefix && library.si_units.include?(parsed_unit) @exponent = library.exponent_for(parsed_unit, prefix.to_sym) @unit_name = parsed_unit.to_sym else @exponent = 1 @unit_name = unit end end |
Instance Attribute Details
#exponent ⇒ Object (readonly)
Returns the value of attribute exponent.
3 4 5 |
# File 'lib/alchemist/prefix_parser.rb', line 3 def exponent @exponent end |
#unit_name ⇒ Object (readonly)
Returns the value of attribute unit_name.
3 4 5 |
# File 'lib/alchemist/prefix_parser.rb', line 3 def unit_name @unit_name end |
Instance Method Details
#guess_type(from) ⇒ Object
27 28 29 |
# File 'lib/alchemist/prefix_parser.rb', line 27 def guess_type(from) shared_types(from).first end |
#prefix_matcher ⇒ Object
19 20 21 |
# File 'lib/alchemist/prefix_parser.rb', line 19 def prefix_matcher @prefix_matcher ||= generate_prefix_matcher end |
#shares_type?(from) ⇒ Boolean
23 24 25 |
# File 'lib/alchemist/prefix_parser.rb', line 23 def shares_type?(from) guess_type(from) end |