On Wed, Jun 24, 2009 at 10:05 AM, ricsrock<ricsrock at gmail.com>
wrote:> Thanks for your help.
I can''t help you without runnable code. A cut-n-paste from deep in
your rails app isn''t so useful.
Anyhow, I wrote a unit test based on your code, and it works fine.
Produce a __runnable, standalone__ example, the exercise might show
you what the problem is, and if not, you would have something you
could send to me.
diff --git a/test/test_vcard.rb b/test/test_vcard.rb
index fad86d3..fd6896d 100755
--- a/test/test_vcard.rb
+++ b/test/test_vcard.rb
@@ -718,6 +718,28 @@ END:VCARD
assert_equal(''well given'', card.name.fullname)
end
+ def test_add_tel
+ phones = ["1", "2", "3"]
+ card = Vpim::Vcard::Maker.make2 do |maker|
+ maker.add_name do |name|
+ name.given = "self.first_name"
+ name.family = "self.last_name"
+ end
+ phones.each do |phone|
+ maker.add_tel(phone) do |tel|
+ tel.location = ''home''
+ tel.preferred = true
+ end
+ end
+ end
+ card = Vpim::Vcard.decode(card.encode).first
+ pp card
+ card.telephones.each do |phone|
+ assert_equal(phone, phones.delete(phone))
+ end
+ assert_equal(0, phones.size)
+ end
+
> This is from an Active Record model. The to_vcard method takes a person
> object and creates a vcard.
> class Person < ActiveRecord::Base
> def to_vcard
> card = Vpim::Vcard::Maker.make2 do |maker|
> maker.add_name do |name|
> name.given = self.first_name
> name.family = self.last_name
> end
> ...
> self.phones.each do |phone|
> maker.add_tel(phone.s_formatted) do |tel|
> tel.location = ''home''
> tel.preferred = true
> end
> end
> end
> card.to_s
> ...
> end
> end
> On Jun 24, 2009, at 11:34 AM, Sam Roberts wrote:
>
> On Wed, Jun 24, 2009 at 7:54 AM, ricsrock <ricsrock at gmail.com>
wrote:
>>
>> I am new to vpim. Using Vpim::Vcard::Maker to create and export vcards
>> from my app. That''s all great except I''m unable to
get vpim to export all
>> the phones (and/or emails) associated with a person''s record.
I would expect
>> to be able to iterate over a collection of phones, for example, and do
>> maker#add_tel for each of them... but that doesn''t seem to
work.
>>
>> This doesn''t work...
>
> The # is a comment, so this isn''t very close to valid ruby code.
>
> If you send a standalone runnable example I can tell you what''s
happening.
>
>
>> card = Vpim::Vcard::Maker#make2 do |maker|
>> ...
>> collection_of_phones#each do |phone|
>> maker#add_tel(phone#number) do |tel|
>> ...
>> end
>> end
>> ...
>> end
>>
>> What am I missing? Thanks for your help.
>
>
>
>
>