Sha256: 73fb9c48dcf0b5e5ad88b64af6229dace67ce89caea95fb9ac27f17fb0ac2c9a

Contents?: true

Size: 597 Bytes

Versions: 22

Compression:

Stored size: 597 Bytes

Contents

require 'rexml/document'

##
# exports contacts in xml format

class Blackbook::Exporter::Xml < Blackbook::Exporter::Base

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

  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
  
  Blackbook.register(:xml, self)
end

Version data entries

22 entries across 22 versions & 5 rubygems

Version Path
blackbook-1.0.0 lib/blackbook/exporter/xml.rb
blackbook-1.0.4 lib/blackbook/exporter/xml.rb