Class: Fonbok::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/fonbok/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Reader

Returns a new instance of Reader.



7
8
9
10
# File 'lib/fonbok/reader.rb', line 7

def initialize(path)
  @path = path
  @doc = Nokogiri::XML(File.open(@path, 'r'))
end

Instance Method Details

#importObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fonbok/reader.rb', line 12

def import
  phonebook_from_xml.tap do |phonebook|
    @doc.xpath('/phonebooks/phonebook/contact').each do |xml_contact|
      contact = contact_from_xml(xml_contact)
      xml_contact.xpath('telephony/number').each do |xml_number|
        number = number_from_xml(xml_number)
        contact.add_number(number)
      end
      phonebook.add_contact(contact)
    end
  end
end

#inspectObject



25
26
27
# File 'lib/fonbok/reader.rb', line 25

def inspect
  "<Fonbok::Reader path: #{@path}>"
end