Creating a company card w / Vpim Gem

I use Vpim to create .vcf files that users can then import into their address books. The problem that I am facing is that the information that their download is intended for the Company, and not for a person, so I need to mark the card as such. Is there a way to do this with Vpim, or is there another stone that I could use to achieve this?

def to_vcf card = Vpim::Vcard::Maker.make2 do |maker| ... end end 

Address card business card source

 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 

Address card business card source

 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 are two main differences in these code examples:

  • ORG: Skate Park Stream;
  • X-ABShowAs: COMPANY

I do not know how this translates to Vpim.

enter image description here

+4
source share
2 answers

Quick and dirty implementation, I hope I understand you 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 do |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 do |maker| maker.add_name do |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 do |contact, idx| File.open("contact#{idx}.vcf", 'w') {|f| f.write(to_vcard(contact)) } end 

Normal vs Company

+3
source

It seems that the creator has an org = method, which you can use to set the ORG. As for X-ABShowAs, the creator has an add_field method. Perhaps you can create your own field (http://vpim.rubyforge.org/classes/Vpim/DirectoryInfo/Field.html).

0
source

All Articles