Skip to content

Commit

Permalink
Merge pull request #10 from brendon/master
Browse files Browse the repository at this point in the history
Added native support for ROLE with escaping
  • Loading branch information
qoobaa committed Jun 18, 2013
2 parents 1f23988 + 0c15b93 commit 1eda8b6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/vcard/vcard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ex2.vcard
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ n:Jensen;Bj=F8rn
email;type=internet:[email protected]
tel;type=work,voice,msg:+1 313 747-4454
key;type=x509;encoding=B:dGhpcyBjb3VsZCBiZSAKbXkgY2VydGlmaWNhdGUK
role:Office Manager\;Something Else
end:VCARD
17 changes: 17 additions & 0 deletions test/vcard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" ])
Expand Down Expand Up @@ -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

0 comments on commit 1eda8b6

Please sign in to comment.