Class: TelephoneNumber::PhoneDataImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/importers/phone_data_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, override: false) ⇒ PhoneDataImporter

Returns a new instance of PhoneDataImporter.



6
7
8
9
10
# File 'lib/importers/phone_data_importer.rb', line 6

def initialize(file_name, override: false)
  @data = {}
  @file = File.open(file_name) { |f| Nokogiri::XML(f) }
  @override = override
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/importers/phone_data_importer.rb', line 4

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/importers/phone_data_importer.rb', line 4

def file
  @file
end

#overrideObject (readonly)

Returns the value of attribute override.



4
5
6
# File 'lib/importers/phone_data_importer.rb', line 4

def override
  @override
end

Instance Method Details

#import!Object



12
13
14
15
# File 'lib/importers/phone_data_importer.rb', line 12

def import!
  parse_main_data
  save_data_file
end

#parse_main_dataObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/importers/phone_data_importer.rb', line 17

def parse_main_data
  file.css('territories territory').each do |territory|
    country_code = territory.attributes['id'].value.to_sym
    @data[country_code] ||= {}

    load_base_attributes(@data[country_code], territory)
    load_references(@data[country_code], territory)
    load_validations(@data[country_code], territory)
    load_formats(@data[country_code], territory)
  end
end