Class: HMachine::Microformat::HCard

Inherits:
POSH::Base show all
Defined in:
lib/hmachine/microformat/hcard.rb

Constant Summary collapse

FRIENDLY_NAME =
"hCard"
WIKI_URL =
"http://microformats.org/wiki/hcard"
XMDP =
'http://microformats.org/profile/hcard'

Constants included from HMachine

PRODID, VERSION

Instance Attribute Summary

Attributes inherited from POSH::Base

#node, #parent, #source

Instance Method Summary collapse

Methods inherited from POSH::Base

#[], [], add_property, #each_pair, #empty?, extract, get_properties, has_many, has_many!, has_one, has_one!, #has_property?, inherited, #initialize, #inspect, many, name, one, parent, properties, #properties, property_of?, remove_nested, search, selector, #to_h, #to_html, #to_s, validate

Methods included from HMachine

#extract, #extract_from, find, #find_in, #found_in?, get, get_document, get_url, map, normalize, #parse, #parse_first, #search, #valid?, #validate

Constructor Details

This class inherits a constructor from HMachine::POSH::Base

Instance Method Details

#organization?Boolean Also known as: company?

Returns:

  • (Boolean)


86
87
88
89
90
# File 'lib/hmachine/microformat/hcard.rb', line 86

def organization?
  if org
    fn == org[:organization_name]
  end
end

#to_vcardObject

tools.ietf.org/html/rfc2426 TODO: Make this less ugly



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/hmachine/microformat/hcard.rb', line 95

def to_vcard
  @vcard = "BEGIN:VCARD\x0D\x0AVERSION:3.0\x0D\x0APRODID:#{HMachine::PRODID}"
  @vcard += "\x0D\x0ANAME:#{node.document.css('title').first.content}" if node.document.css('title').first
  @vcard += "\x0D\x0ASOURCE:#{@source}" if @source
  @vcard += "\x0D\x0AFN:#{fn}" if fn
  @vcard += n_vcard if n
  if nickname
    @vcard += "\x0D\x0ANICKNAME" + (nickname.respond_to?(:join) ? nickname.join(',') : nickname)
  end
  @vcard += "\x0D\x0APHOTO;VALUE=uri:#{photo.first}" if photo
  @vcard += "\x0D\x0ABDAY:#{bday.strftime('%Y-%m-%d')}" if bday
  if adr
    if adr.respond_to?(:each)
      adr.each { |address| @vcard += adr_vcard(address) }
    else
      @vcard += adr_vcard(adr)
    end           
  end
  if tel
    if tel.respond_to?(:join)
      tel.each { |phone| @vcard += "\x0D\x0ATEL#{type_value_vcard(phone)}" }
    else
      @vcard += "\x0D\x0ATEL#{type_value_vcard(phone)}"
    end
  end
  if email
    if email.respond_to?(:join)
      email.each { |mail| @vcard += "\x0D\x0AEMAIL#{type_value_vcard(mail)}" }
    else
      @vcard += "\x0D\x0AEMAIL#{type_value_vcard(email)}"
    end
  end
  mailer.each {|software| @vcard += "\x0D\x0AMAILER:#{software}" } if mailer
  @vcard += "\x0D\x0ATZ:#{tz}" if tz
  @vcard += "\x0D\x0AGEO:#{geo[:latitude]};#{geo[:longitude]}" if geo
  title.each {|titl| @vcard += "\x0D\x0ATITLE:#{titl}" } if title
  role.each {|roll| @vcard += "\x0D\x0AROLE:#{roll}" } if role
  .each { |log| @vcard += "\x0D\x0ALOGO;VALUE=uri:#{log}" } if 
  agent.each {|mrsmith| @vcard += "\x0D\x0AAGENT:#{mrsmith}" } if agent
  @vcard += "\x0D\x0AORG:#{org[:organization_name]};#{org[:organization_unit]}" if org
  @vcard += "\x0D\x0ACATEGORIES:#{join_vcard_values(category).upcase}" if category
  note.each {|notes| @vcard += "\x0D\x0ANOTE:#{notes}" } if note
  @vcard += "\x0D\x0AREV:#{rev.iso8601}" if rev
  @vcard += "\x0D\x0ASORT-STRING:#{sort_string}" if sort_string
  sound.each {|audio| @vcard += "\x0D\x0ASOUND;VALUE=uri:#{audio}" } if sound
  @vcard += "\x0D\x0AUID:#{uid}" if uid
  url.each {|web| @vcard += "\x0D\x0AURL:#{web}" } if url
  @vcard += "\x0D\x0ACLASS:#{to_h[:class]}" if has_property?(:class)
  key.each {|auth| @vcard += "\x0D\x0AKEY:#{key}" }if key
  @vcard += "\x0D\x0AEND:VCARD\x0D\x0A\x0D\x0A"
end