Class: TapeMeasure::Parser
- Inherits:
-
Object
- Object
- TapeMeasure::Parser
- Defined in:
- lib/tape_measure/parser.rb
Overview
Parse Strings into units and math them
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(string) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(string) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 14 |
# File 'lib/tape_measure/parser.rb', line 10 def initialize(string) @string = string return @string.blank? if @string == 0.0 parse end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'lib/tape_measure/parser.rb', line 8 def value @value end |
Instance Method Details
#parse ⇒ Object
16 17 18 19 20 |
# File 'lib/tape_measure/parser.rb', line 16 def parse @value = LengthGrammar.parse(@string.strip).value rescue => ex ex. end |