class Alchemist::ConversionTable

Public Instance Methods

load_all(yaml_file) click to toggle source
# File lib/alchemist/conversion_table.rb, line 6
def load_all(yaml_file)
  begin
    YAML.load_file(yaml_file).merge(proc_based)
  rescue Psych::SyntaxError, Errno::ENOENT
    nil
  end
end

Private Instance Methods

celsius_conversion() click to toggle source
# File lib/alchemist/conversion_table.rb, line 53
def celsius_conversion
  [to_celsius, from_celsius]
end
fahrenheit_conversion() click to toggle source
# File lib/alchemist/conversion_table.rb, line 65
def fahrenheit_conversion
  [to_fahrenheit, from_fahrenheit]
end
from_celsius() click to toggle source
# File lib/alchemist/conversion_table.rb, line 49
def from_celsius
  lambda{ |t| t - 273.15 }
end
from_fahrenheit() click to toggle source
# File lib/alchemist/conversion_table.rb, line 61
def from_fahrenheit
  lambda{ |t| (t - 273.15) * (9.0/5.0) + 32.0 }
end
proc_based() click to toggle source
# File lib/alchemist/conversion_table.rb, line 16
def proc_based
  {
    :density => {
      :specific_gravity => 1, :sg => 1,
      :brix     => [lambda{ |d| -261.3 / (d - 261.3) }, lambda{ |d| 261.3 - (261.3 / d) }],
      :plato    => [lambda{ |d| -260.0 / (d - 260.0) }, lambda{ |d| 260.0 - (260.0 / d) }],
      :baume    => [lambda{ |d| -145.0 / (d - 145.0) }, lambda{ |d| 145.0 - (145.0 / d) }]
    },
    :temperature => temperature
  }
end
temperature() click to toggle source
# File lib/alchemist/conversion_table.rb, line 28
def temperature
  {
    :kelvin => 1.0, :K => 1.0,

    :celsius => celsius_conversion,
    :centrigrade => celsius_conversion,
    :degree_celsius => celsius_conversion,
    :degree_centrigrade => celsius_conversion,
    :degrees_celsius => celsius_conversion,
    :degrees_centrigrade => celsius_conversion,
    :fahrenheit => fahrenheit_conversion,
    :degree_fahrenheit => fahrenheit_conversion,
    :degrees_fahrenheit => fahrenheit_conversion,
    :rankine => 1.8, :rankines => 1.8
  }
end
to_celsius() click to toggle source
# File lib/alchemist/conversion_table.rb, line 45
def to_celsius
  lambda{ |t| t + 273.15 }
end
to_fahrenheit() click to toggle source
# File lib/alchemist/conversion_table.rb, line 57
def to_fahrenheit
  lambda{ |t| (t - 32.0) * (5.0/9.0) + 273.15 }
end