class FeedParser::HyBuilder
Attributes
feeds[R]
Public Class Methods
new( hash )
click to toggle source
# File lib/feedparser/builder/microformats.rb, line 141 def initialize( hash ) @h = hash @feeds = [] build pp @feeds end
Public Instance Methods
build()
click to toggle source
# File lib/feedparser/builder/microformats.rb, line 149 def build entries = [] @h['items'].each_with_index do |item_hash,i| puts "item #{i+1}:" pp item_hash types = item_hash['type'] pp types if types.include?( 'h-feed' ) @feeds << build_feed( item_hash ) elsif types.include?( 'h-entry' ) entries << build_entry( item_hash ) else ## unknown type; skip for now end end ## wrap all "loose" entries in a "dummy" h-entry feed if entries.any? feed = HyFeed.new feed.entries = entries @feeds << feed end end
build_entry( h )
click to toggle source
# File lib/feedparser/builder/microformats.rb, line 198 def build_entry( h ) puts " build_entry" entry = HyEntry.new props = h['properties'] pp props entry.name = props['name'].join( ' ') # check an example with more entries (how to join??) if props['summary'] entry.summary = props['summary'].join( ' ' ) end if props['content'] ## add up all value attribs in content entry.content_text = props['content'].map { |h| h[:value] }.join( ' ' ).strip ## add up all html attribs in content; plus strip leading n trailing whitespaces entry.content = props['content'].map { |h| h[:html] }.join( ' ' ).strip end # get first field in array -- check if really ever possible more than one? what does it mean (many dates)??? ## todo: check if datetime is always utc (or local possible?) url_str = props.fetch( 'url', [] )[0] if url_str entry.url = url_str end # get first field in array -- check if really ever possible more than one? what does it mean (many dates)??? ## todo: check if datetime is always utc (or local possible?) published_str = props.fetch( 'published', [] )[0] pp published_str if published_str ## entry.published = DateTime.iso8601( published_str ) entry.published_local = DateTime.parse( published_str ) entry.published = entry.published_local.utc end ## check for authors if props['author'] props['author'].each do |author_hash| pp author_hash entry.authors << build_author( author_hash ) end end entry end
build_feed( h )
click to toggle source
# File lib/feedparser/builder/microformats.rb, line 176 def build_feed( h ) puts " build_feed" feed = HyFeed.new h['children'].each_with_index do |item_hash,i| puts "item #{i+1}:" pp item_hash types = item_hash['type'] pp types if types.include?( 'h-entry' ) feed.entries << build_entry( item_hash ) else ## unknown type; skip for now end end feed end