Class: Worldwide::RegionsLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/worldwide/regions_loader.rb

Constant Summary collapse

WORLD_CODE =

UN code for the whole world

"001"

Instance Method Summary collapse

Instance Method Details

#load_regionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/worldwide/regions_loader.rb', line 11

def load_regions
  # Load country/region definitions out of the db/data/regions/??.yml files
  @regions = Dir["#{Worldwide::Paths::REGIONS_ROOT}/*.yml"].map do |filename|
    load_territory(filename)
  end.flatten

  # Load hierarchies out of world.yml, and construct regions to match the specified hierarchies
  apply_hierarchy(parent: nil, code: WORLD_CODE, children: world_yml[WORLD_CODE])
  world_yml["alternates"].each do |code, children|
    apply_hierarchy(parent: nil, code: code, children: children)
  end

  # Construct regions to represent trading blocks like the EU
  construct_trading_blocks

  construct_unknown

  @regions.freeze
end