Sha256: be60cc6dc5eaa2845b3f753f7ea3558c248d02bf0869ed5c6d4523cfaea7ae8f

Contents?: true

Size: 951 Bytes

Versions: 17

Compression:

Stored size: 951 Bytes

Contents

##
# exports contacts in Vcard format
class Blackbook::Exporter::Vcf < Blackbook::Exporter::Base

  ##
  # representation of a vcard

  class Vcard

    attr_accessor :first, :last, :email
    
    ##
    # initialize dynamically sets the attributes passed in as accessible 
    # attribute on its object

    def initialize( attributes = {} )
      attributes.each{ |name,value| self.send("#{name}=", value) rescue next }
    end
    
    ##
    # text representation of this vcard
    def to_s
      <<-EOVC
BEGIN:VCARD
N:#{last};#{first}
EMAIL:#{email}
END:VCARD
      EOVC
    end
  end

  ##
  # exports contacts as Vcards

  def export( contacts = [] )
    return if contacts.empty? 
    
    contacts.uniq.compact.collect do |contact|
      first_name, last_name = contact[:name].split(' ', 2)
      Vcard.new( :first => first_name.to_s, :last => last_name.to_s, :email => contact[:email])
    end
  end
  
  Blackbook.register(:vcf, self)
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
alexjp-blackbook_csv-1.0.5 lib/blackbook/exporter/vcf.rb
alexjp-blackbook_csv-3.0.1 lib/blackbook/exporter/vcf.rb
alexjp-blackbook_csv-3.0.2 lib/blackbook/exporter/vcf.rb
bcardarella-blackbook-1.0.10 lib/blackbook/exporter/vcf.rb
bcardarella-blackbook-1.0.11 lib/blackbook/exporter/vcf.rb
bcardarella-blackbook-1.0.7 lib/blackbook/exporter/vcf.rb
bcardarella-blackbook-1.0.8 lib/blackbook/exporter/vcf.rb
bcardarella-blackbook-1.0.9 lib/blackbook/exporter/vcf.rb
briancollins-blackbook-1.0.15 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.12 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.13 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.14 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.15 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.16 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.17 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.18 lib/blackbook/exporter/vcf.rb
rakutenusa-blackbook-1.0.19 lib/blackbook/exporter/vcf.rb