Class: GlobalPhone::DatabaseGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/global_phone/database_generator.rb

Constant Summary collapse

VERSION =
'1.0.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ DatabaseGenerator

Returns a new instance of DatabaseGenerator.



18
19
20
# File 'lib/global_phone/database_generator.rb', line 18

def initialize(doc)
  @doc = doc
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



16
17
18
# File 'lib/global_phone/database_generator.rb', line 16

def doc
  @doc
end

Class Method Details

.load(xml) ⇒ Object



12
13
14
# File 'lib/global_phone/database_generator.rb', line 12

def self.load(xml)
  new(Nokogiri.XML(xml))
end

.load_file(filename) ⇒ Object



8
9
10
# File 'lib/global_phone/database_generator.rb', line 8

def self.load_file(filename)
  load(File.read(filename))
end

Instance Method Details

#inspectObject



34
35
36
# File 'lib/global_phone/database_generator.rb', line 34

def inspect
  "#<#{self.class.name} (#{doc.search("*").size} elements)>"
end

#record_dataObject



28
29
30
31
32
# File 'lib/global_phone/database_generator.rb', line 28

def record_data
  @record_data ||= territory_nodes_by_region.map do |country_code, territory_nodes|
    truncate(compile_region(territory_nodes, country_code))
  end
end

#test_casesObject



22
23
24
25
26
# File 'lib/global_phone/database_generator.rb', line 22

def test_cases
  @test_cases ||= territory_nodes.map do |node|
    example_numbers_for_territory_node(node)
  end.flatten(1)
end