ruby on rails - Create Company Card w/ Vpim Gem -
i'm using vpim generate .vcf files users can import address books. problem i'm having information downloading company , not person need mark card being such. there way using vpim or there gem use accomplish this?
def to_vcf card = vpim::vcard::maker.make2 |maker| ... end end
source of business card address book
begin:vcard version:3.0 n:;;;; fn:the flow skatepark org:the flow skatepark; item1.tel;type=pref:(614) 864-1610 item1.x-ablabel:work # item2.adr;type=work;type=pref:;;4252 groves rd;columbus;oh;43232;usa item2.x-abadr:us bday;value=date:2001-07-06 x-abshowas:company x-abuid:5f7349cb-369f-4eac-ab65-49ed902bef9f\:abperson end:vcard
source of non-business card address book
begin:vcard version:3.0 n:;the flow skatepark;;; fn:the flow skatepark item1.tel;type=pref:(614) 864-1610 item1.x-ablabel:work # item2.adr;type=work;type=pref:;;4252 groves rd;columbus;oh;43232;usa item2.x-abadr:us bday;value=date:2001-07-06 x-abuid:5f7349cb-369f-4eac-ab65-49ed902bef9f\:abperson end:vcard
obviously there 2 main differences in these code samples:
- org:the flow skatepark;
- x-abshowas:company
i don't know how translates vpim however.
quick , dirty implementation, hope understood correctly:
require 'vpim/vcard' vcards = <<vcard begin:vcard version:3.0 n:;;;; fn:the flow skatepark org:the flow skatepark; item1.tel;type=pref:(614) 864-1610 item1.x-ablabel:work # item2.adr;type=work;type=pref:;;4252 groves rd;columbus;oh;43232;usa item2.x-abadr:us bday;value=date:2001-07-06 x-abshowas:company x-abuid:5f7349cb-369f-4eac-ab65-49ed902bef9f\:abperson end:vcard begin:vcard version:3.0 n:;the flow skatepark;;; fn:the flow skatepark item1.tel;type=pref:(614) 864-1610 item1.x-ablabel:work # item2.adr;type=work;type=pref:;;4252 groves rd;columbus;oh;43232;usa item2.x-abadr:us bday;value=date:2001-07-06 x-abuid:5f7349cb-369f-4eac-ab65-49ed902bef9f\:abperson end:vcard vcard contacts = [] vpim::vcard.decode(vcards).each |vcard| contacts << { first_name: vcard.name ? vcard.name.given : '', last_name: vcard.name ? vcard.name.family : '', organisation_name: vcard.org ? vcard.org.first : '', } end def to_vcard(card) vpim::vcard::maker.make2 |maker| maker.add_name |name| name.given = card[:first_name] unless card[:first_name].empty? || card[:first_name].nil? name.family = card[:last_name] unless card[:last_name].empty? || card[:last_name].nil? end maker.org = card[:organisation_name] unless card[:organisation_name].empty? || card[:organisation_name].nil? end end contacts.each_with_index |contact, idx| file.open("contact#{idx}.vcf", 'w') {|f| f.write(to_vcard(contact)) } end
Comments
Post a Comment