Skip to content

Commit

Permalink
format hcard addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
josephholsten committed Nov 2, 2012
1 parent bd61dee commit 3206f2b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bin/webfinger
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ else
log.warn("Disco doc didn't list a subject. Assuming everything is well.") log.warn("Disco doc didn't list a subject. Assuming everything is well.")
end end



def format_address(adr)
segments = []
segments << adr.street_address if adr.properties.include?(:street_address)
segments << adr.locality if adr.properties.include?(:locality)
segments << adr.region if adr.properties.include?(:region)
segments << adr.postal_code if adr.properties.include?(:postal_code)
segments << adr.country_name if adr.properties.include?(:country_name)
segments.join(' ')
end


hcard_uri = disco.uris_by_rel('http://microformats.org/profile/hcard').first hcard_uri = disco.uris_by_rel('http://microformats.org/profile/hcard').first
hcards = Prism.find(hcard_uri, :hcard) hcards = Prism.find(hcard_uri, :hcard)
Expand All @@ -85,6 +93,7 @@ hcards.each do |hcard|
puts "Name: #{hcard.fn.gsub(/\s+/, ' ')}" if hcard.properties.include?(:fn) puts "Name: #{hcard.fn.gsub(/\s+/, ' ')}" if hcard.properties.include?(:fn)
puts "Title: #{hcard.title}" if hcard.properties.include?(:title) puts "Title: #{hcard.title}" if hcard.properties.include?(:title)
puts "Organization: #{hcard.org}" if hcard.properties.include?(:org) puts "Organization: #{hcard.org}" if hcard.properties.include?(:org)
puts "Address: #{format_address(hcard.adr)}" if hcard.properties.include?(:adr)
end end
end end


Expand Down

0 comments on commit 3206f2b

Please sign in to comment.