Class: Blackbook::Exporter::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/blackbook/exporter/xml.rb

Overview

exports contacts in xml format

Instance Method Summary collapse

Instance Method Details

#export(contacts) ⇒ Object

contacts are an array of hashes that are contacts and returns xml



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/blackbook/exporter/xml.rb', line 11

def export( contacts )
  doc = REXML::Document.new
  doc << REXML::XMLDecl.new
  
  root = doc.add_element 'contacts'
  contacts.each do |contact|
    el = root.add_element 'contact'
    name = el.add_element 'name' 
    name.text = contact[:name]
    
    el.add_element('email').text = contact[:email]
  end
  
  doc.to_s
end