使用 Vpim Gem 创建公司卡

发布于 2024-11-18 09:03:13 字数 1255 浏览 2 评论 0原文

我使用 Vpim 生成 .vcf 文件,然后用户可以将其导入到他们的地址簿中。我遇到的问题是,他们下载的信息是针对公司而不是个人的,因此我需要将卡标记为此类。有没有办法使用 Vpim 来做到这一点,或者我可以使用另一种 gem 来实现这一点?

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

地址簿中的名片来源

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

显然,这些代码示例有两个主要区别:

  • ORG:The Flow Skatepark;
  • X-ABSShowAs:COMPANY

但是我不知道这如何转化为 Vpim。

在此处输入图像描述

I'm using Vpim to generate .vcf files that users can then import into their address books. The problem that I'm having is that the information that their downloading is for a Company and not a person so I need to mark the card as being such. Is there a way to do this using Vpim or is there another gem that I could use to accomplish this?

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

Source of a Business Card from 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 a Non-Business Card from 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 are two main differences in these code samples:

  • ORG:The Flow Skatepark;
  • X-ABShowAs:COMPANY

I don't know how this translates into Vpim however.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回首观望 2024-11-25 09:03:13

快速而肮脏的实施,我希望我正确理解你:

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

Quick and dirty implementation, I hope that I understood 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

鹤仙姿 2024-11-25 09:03:13

看起来maker对象有一个org=方法,你可以用它来设置ORG。至于X-ABShowAs,maker有一个add_field方法。您可以为此创建自己的字段(http://vpim.rubyforge.org/classes/Vpim/DirectoryInfo/Field.html)。

Looks like the maker object has a org= method, which you can use to set ORG. As for X-ABShowAs, maker has an add_field method. You can probably create your own field (http://vpim.rubyforge.org/classes/Vpim/DirectoryInfo/Field.html) for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文