Ruby vcard maker


/ Published in: Ruby
Save to your folder(s)

Requires vPim package.


Copy this code and paste it in your HTML
  1. require 'vpim/vcard'
  2.  
  3. card = Vpim::Vcard::Maker.make2 do |maker|
  4. maker.add_name do |name|
  5. name.prefix = 'Dr.'
  6. name.given = 'Jimmy'
  7. name.family = 'Death'
  8. end
  9.  
  10. maker.add_addr do |addr|
  11. addr.preferred = true
  12. addr.location = 'work'
  13. addr.street = '12 Last Row, 13th Section'
  14. addr.locality = 'City of Lost Children'
  15. addr.country = 'Cinema'
  16. end
  17.  
  18. maker.add_addr do |addr|
  19. addr.location = [ 'home', 'zoo' ]
  20. addr.delivery = [ 'snail', 'stork', 'camel' ]
  21. addr.street = '12 Last Row, 13th Section'
  22. addr.locality = 'City of Lost Children'
  23. addr.country = 'Cinema'
  24. end
  25.  
  26. maker.nickname = "The Good Doctor"
  27.  
  28. maker.birthday = Date.today
  29.  
  30. maker.add_photo do |photo|
  31. photo.link = 'http://example.com/image.png'
  32. end
  33.  
  34. maker.add_photo do |photo|
  35. photo.image = "File.open('drdeath.jpg').read # a fake string, real data is too large :-)"
  36. photo.type = 'jpeg'
  37. end
  38.  
  39. maker.add_tel('416 123 1111')
  40.  
  41. maker.add_tel('416 123 2222') { |t| t.location = 'home'; t.preferred = true }
  42.  
  43. maker.add_impp('joe') do |impp|
  44. impp.preferred = 'yes'
  45. impp.location = 'mobile'
  46. end
  47.  
  48. maker.add_x_aim('example') do |xaim|
  49. xaim.location = 'row12'
  50. end
  51.  
  52. maker.add_tel('416-123-3333') do |tel|
  53. tel.location = 'work'
  54. tel.capability = 'fax'
  55. end
  56.  
  57. maker.add_email('[email protected]') { |e| e.location = 'work' }
  58.  
  59. maker.add_email('[email protected]') { |e| e.preferred = 'yes' }
  60.  
  61. end
  62.  
  63. puts card

URL: http://vpim.rubyforge.org/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.