Class: ContactSport::VcardReader
- Inherits:
-
Object
- Object
- ContactSport::VcardReader
- Defined in:
- lib/contact_sport/vcard_reader.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #contacts ⇒ Object
-
#initialize(file) ⇒ VcardReader
constructor
A new instance of VcardReader.
Constructor Details
#initialize(file) ⇒ VcardReader
Returns a new instance of VcardReader.
9 10 11 |
# File 'lib/contact_sport/vcard_reader.rb', line 9 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/contact_sport/vcard_reader.rb', line 7 def file @file end |
Instance Method Details
#contacts ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/contact_sport/vcard_reader.rb', line 13 def contacts begin @contacts ||= Vcard::Vcard.decode(contents).map do |card| Contact.new( first_name: card.name.given, last_name: card.name.family, name: card.name.fullname, email: email(card), url: url(card), company: company(card), office_phone: work_phone(card), mobile_phone: mobile_phone(card), fax: fax(card), address1: address_first_line(card), address2: address_second_line(card), city: address(:locality, card), region: address(:region, card), postcode: address(:postalcode, card), country: address(:country, card) ) end rescue Vcard::InvalidEncodingError, Vcard::UnsupportedError, Vcard::Unencodeable => e raise ContactSport::FormatError, e. end end |