Class: Contacts::Vcf

Inherits:
Base
  • Object
show all
Defined in:
lib/contacts/vcf.rb

Instance Method Summary collapse

Methods inherited from Base

#connect, #connected?, #login, #password, #skip_gzip?

Constructor Details

#initialize(file) ⇒ Vcf

Returns a new instance of Vcf.



4
5
6
# File 'lib/contacts/vcf.rb', line 4

def initialize(file)
  @contact_file = file
end

Instance Method Details

#contactsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/contacts/vcf.rb', line 8

def contacts
  contacts = Array.new
  i = 0
  @contact_file.each do |line|
    contacts[i] = Array.new unless contacts[i]
    if line.match(/FN:/)
      contacts[i] << line.gsub(/FN:/, '').strip
    elsif line.match(/EMAIL;/)
      contacts[i] << line.gsub(/^.*:/, '').strip
    elsif line.match(/END:VCARD/)
      i += 1
    end
  end
  contacts
end