Class: YouTubeG::Parser::CommentsFeedParser

Inherits:
FeedParser
  • Object
show all
Defined in:
lib/youtube_g/parser.rb

Instance Method Summary collapse

Methods inherited from FeedParser

#initialize, #parse

Constructor Details

This class inherits a constructor from YouTubeG::Parser::FeedParser

Instance Method Details

#parse_content(content) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/youtube_g/parser.rb', line 194

def parse_content(content)
  doc = REXML::Document.new(content)
  feed = doc.elements['feed']
  
  feed_id            = feed.elements["id"].text
  updated_at         = Time.parse(feed.elements["updated"].text)
  total_result_count = feed.elements["openSearch:totalResults"].text.to_i
  offset             = feed.elements["openSearch:startIndex"].text.to_i
  max_result_count   = feed.elements["openSearch:itemsPerPage"].text.to_i
  
  comments = []
  feed.elements.each('entry') do |entry|
    comments << parse_entry(entry)
  end
  YouTubeG::Response::CommentsSearch.new(
    :feed_id            => feed_id,
    :updated_at         => updated_at,
    :total_result_count => total_result_count,
    :offset             => offset,
    :max_result_count   => max_result_count,
    :comments           => comments)
end