Class: Phonejack::DataImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/phonejack/data_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, override: false) ⇒ DataImporter

Returns a new instance of DataImporter.



6
7
8
9
10
# File 'lib/phonejack/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/phonejack/data_importer.rb', line 4

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/phonejack/data_importer.rb', line 4

def file
  @file
end

#overrideObject (readonly)

Returns the value of attribute override.



4
5
6
# File 'lib/phonejack/data_importer.rb', line 4

def override
  @override
end

Instance Method Details

#import!Object



12
13
14
15
# File 'lib/phonejack/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/phonejack/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