Method: Unit::System#load

Defined in:
lib/unit/system.rb

#load(input) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/unit/system.rb', line 24

def load(input)
  case input
  when Hash
    data = input
  when IO
    data = YAML.load(input.read)
  when String
    if File.exist?(input)
      return if @loaded_filenames.include?(input)
      data = YAML.load_file(input)
      @loaded_filenames << input
    else
      load(input.to_sym)
      return
    end
  when Symbol
    return if @loaded_systems.include?(input)
    data = YAML.load_file(File.join(File.dirname(__FILE__), 'systems', "#{input}.yml"))
    @loaded_systems << input
  end

  load_factors(data['factors']) if data['factors']
  load_units(data['units']) if data['units']

  @unit.each {|name, unit| validate_unit(unit[:def]) }

  true
end