class Alchemist::MeasurementConvertor
Attributes
from[R]
Public Class Methods
new(from)
click to toggle source
# File lib/alchemist/measurement_convertor.rb, line 6 def initialize from @from = from end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
# File lib/alchemist/measurement_convertor.rb, line 10 def method_missing method, *args, &block parsed_unit = parse_prefix(method) convert(parsed_unit) end
Private Instance Methods
convert(parsed_unit)
click to toggle source
# File lib/alchemist/measurement_convertor.rb, line 23 def convert parsed_unit if parsed_unit.shares_type?(from) ConversionCalculator.new(from, parsed_unit).calculate else raise IncompatibleTypeError, "Incompatible Types" end end
parse_prefix(name)
click to toggle source
# File lib/alchemist/measurement_convertor.rb, line 18 def parse_prefix(name) PrefixParser.new(name) end