Module: Elibri::ONIX::Dict::Release_3_0

Extended by:
Release_3_0
Included in:
Release_3_0
Defined in:
lib/elibri_onix_dict.rb,
lib/elibri_onix_dict/onix_3_0/base.rb

Defined Under Namespace

Classes: Base

Instance Method Summary collapse

Instance Method Details

#load_dictionaries!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elibri_onix_dict.rb', line 14

def load_dictionaries!
  serialized_path = File.join(File.dirname(__FILE__), "elibri_onix_dict", "onix_3_0", "serialized", "*.yml")
  serialized_path = File.expand_path(serialized_path)

  Dir[serialized_path].each do |file|
    klass_name = File.basename(file, '.yml') # 'ResourceMode'
    klass = Class.new(Elibri::ONIX::Dict::Release_3_0::Base)
    # Elibri::ONIX::Dict::Release_3_0::ResourceMode
    const_set(klass_name, klass)

    if RUBY_VERSION[0] == "2"
      klass.const_set(:ALL, YAML::load_file(file))
    else
      klass.const_set(:ALL, YAML::load_file(file, permitted_classes: [klass]))
    end

    klass::ALL.each do |dict_item|
      klass.const_set(dict_item.const_name, dict_item.onix_code) if dict_item.const_name
    end
  end
end