From 11d3a08e62ad2a2261f597f42b7052af0c1aa52a Mon Sep 17 00:00:00 2001 From: Brendon Muir Date: Tue, 18 Jun 2013 23:09:30 +1200 Subject: [PATCH 1/2] Fix superfluous comma --- lib/vcard/vcard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vcard/vcard.rb b/lib/vcard/vcard.rb index 57a0719..d7358ec 100644 --- a/lib/vcard/vcard.rb +++ b/lib/vcard/vcard.rb @@ -531,7 +531,7 @@ def decode_attachment(field) #:nodoc: "TITLE" => :decode_text, "UID" => :decode_text, "URL" => :decode_uri, - "VERSION" => :decode_version, + "VERSION" => :decode_version } @@decode.default = :decode_default From 0c15b9320a57a198a96dd4fecaad6b11ce308609 Mon Sep 17 00:00:00 2001 From: Brendon Muir Date: Tue, 18 Jun 2013 23:22:15 +1200 Subject: [PATCH 2/2] Added native support for ROLE --- lib/vcard/vcard.rb | 12 ++++++++++++ test/fixtures/ex2.vcard | 1 + test/vcard_test.rb | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/lib/vcard/vcard.rb b/lib/vcard/vcard.rb index d7358ec..543d5f2 100644 --- a/lib/vcard/vcard.rb +++ b/lib/vcard/vcard.rb @@ -950,6 +950,10 @@ def version v end + def role + value("ROLE") + end + # Make changes to a vCard. # # Yields a Vcard::Vcard::Maker that can be used to modify this vCard. @@ -1314,6 +1318,14 @@ def org=(org) @card << ::Vcard::DirectoryInfo::Field.create( "ORG", org ); end + # Set the role field, ROLE. + # + # It can be set to a single String. + def role=(role) + delete_if { |l| l.name == "ROLE" } + + @card << ::Vcard::DirectoryInfo::Field.create( "ROLE", ::Vcard.encode_text(role)); + end # Add a URL field, URL. def add_url(url) diff --git a/test/fixtures/ex2.vcard b/test/fixtures/ex2.vcard index 99cc31e..4674336 100644 --- a/test/fixtures/ex2.vcard +++ b/test/fixtures/ex2.vcard @@ -6,4 +6,5 @@ n:Jensen;Bj=F8rn email;type=internet:bjorn@umich.edu tel;type=work,voice,msg:+1 313 747-4454 key;type=x509;encoding=B:dGhpcyBjb3VsZCBiZSAKbXkgY2VydGlmaWNhdGUK +role:Office Manager\;Something Else end:VCARD diff --git a/test/vcard_test.rb b/test/vcard_test.rb index cdd0bfa..fb8cfb8 100644 --- a/test/vcard_test.rb +++ b/test/vcard_test.rb @@ -30,6 +30,7 @@ def test_ex2 assert_equal("Jensen", card.name.family) assert_equal("Bj=F8rn", card.name.given) assert_equal("", card.name.prefix) + assert_equal('Office Manager;Something Else', card.role) assert_equal("Bj=F8rn Jensen", card[ "fn" ]) assert_equal("+1 313 747-4454", card[ "tEL" ]) @@ -482,4 +483,20 @@ def test_org_single def test_org_multiple _test_org("Megamix Corp.", "Marketing") end + + def test_role + role = 'Office Manager;Something Else' + + card = Vcard::Vcard::Maker.make2 do |m| + m.name do |n| + n.given = "John" + n.family = "Woe" + end + m.role = 'Office Manager;Something Else' + end + assert_equal(role, card.role) + assert(card.to_s['Office Manager\;Something Else']) + card = Vcard::Vcard.decode(card.encode).first + assert_equal(role, card.role) + end end