Class: TapeMeasure::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/tape_measure/parser.rb

Overview

Parse Strings into units and math them

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#valueObject (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

#parseObject



16
17
18
19
20
# File 'lib/tape_measure/parser.rb', line 16

def parse
  @value = LengthGrammar.parse(@string.strip).value
rescue => ex
  ex.message
end