Class: Height::Parser
- Inherits:
-
Object
- Object
- Height::Parser
- Defined in:
- lib/height/parser.rb
Instance Method Summary collapse
- #centimeters ⇒ Object
- #feet ⇒ Object
- #inches ⇒ Object
-
#initialize(input) ⇒ Parser
constructor
A new instance of Parser.
- #meters ⇒ Object
- #millimeters ⇒ Object
Constructor Details
#initialize(input) ⇒ Parser
Returns a new instance of Parser.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/height/parser.rb', line 3 def initialize(input) @input = input metric_parser = Parsers::Metric.new(@input) imperial_parser = Parsers::Imperial.new(@input) if metric_parser.parsed? @millimeters = metric_parser.millimeters elsif imperial_parser.parsed? @millimeters = imperial_parser.inches.to_millimeters else raise ArgumentError.new("Could not parse `#{@input}` into valid height") end end |
Instance Method Details
#centimeters ⇒ Object
22 23 24 |
# File 'lib/height/parser.rb', line 22 def centimeters millimeters.to_centimeters end |
#feet ⇒ Object
34 35 36 |
# File 'lib/height/parser.rb', line 34 def feet millimeters.to_feet end |
#inches ⇒ Object
30 31 32 |
# File 'lib/height/parser.rb', line 30 def inches millimeters.to_inches end |
#meters ⇒ Object
26 27 28 |
# File 'lib/height/parser.rb', line 26 def meters millimeters.to_meters end |
#millimeters ⇒ Object
18 19 20 |
# File 'lib/height/parser.rb', line 18 def millimeters @millimeters end |