Class: Sources::Local::Subdivision

Inherits:
Object
  • Object
show all
Defined in:
lib/countries/sources/local/subdivision.rb

Overview

Auxiliary Subdivision class to support loading the local subdivision data to be updated with Unicode CLDR data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Subdivision

Returns a new instance of Subdivision.



9
10
11
# File 'lib/countries/sources/local/subdivision.rb', line 9

def initialize(code)
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/countries/sources/local/subdivision.rb', line 7

def code
  @code
end

Class Method Details

.load(code) ⇒ Object



31
32
33
# File 'lib/countries/sources/local/subdivision.rb', line 31

def self.load(code)
  new(code).load
end

Instance Method Details

#file_pathObject



27
28
29
# File 'lib/countries/sources/local/subdivision.rb', line 27

def file_path
  "lib/countries/data/subdivisions/#{code}.yaml"
end

#loadObject



13
14
15
16
17
18
19
# File 'lib/countries/sources/local/subdivision.rb', line 13

def load
  if File.exist?(file_path)
    YAML.load_file(file_path) || {}
  else
    {}
  end
end

#save(data) ⇒ Object



21
22
23
24
25
# File 'lib/countries/sources/local/subdivision.rb', line 21

def save(data)
  File.write(file_path, data.to_yaml)
rescue StandardError
  puts "failed to read #{file}: #{$ERROR_INFO}"
end