Class: FeedParser::HyBuilder
- Inherits:
-
Object
- Object
- FeedParser::HyBuilder
- Defined in:
- lib/feedparser/builder/microformats.rb
Instance Attribute Summary collapse
-
#feeds ⇒ Object
readonly
Returns the value of attribute feeds.
Instance Method Summary collapse
- #build ⇒ Object
-
#build_author(h) ⇒ Object
method build_entry.
- #build_entry(h) ⇒ Object
-
#build_feed(h) ⇒ Object
method build.
-
#initialize(hash) ⇒ HyBuilder
constructor
A new instance of HyBuilder.
Constructor Details
#initialize(hash) ⇒ HyBuilder
Returns a new instance of HyBuilder.
141 142 143 144 145 146 147 |
# File 'lib/feedparser/builder/microformats.rb', line 141 def initialize( hash ) @h = hash @feeds = [] build pp @feeds end |
Instance Attribute Details
#feeds ⇒ Object (readonly)
Returns the value of attribute feeds.
139 140 141 |
# File 'lib/feedparser/builder/microformats.rb', line 139 def feeds @feeds end |
Instance Method Details
#build ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# 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_author(h) ⇒ Object
method build_entry
248 249 250 251 252 253 254 255 256 257 |
# File 'lib/feedparser/builder/microformats.rb', line 248 def ( h ) puts " build_author" = HyAuthor.new .name = h['value'] ## todo/fix: -- note: for now skip possible embedded h-card end |
#build_entry(h) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# 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 || pp entry. << ( ) end end entry end |
#build_feed(h) ⇒ Object
method build
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# 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 |