Class: YouTubeIt::Parser::FeedParser

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ FeedParser

Returns a new instance of FeedParser.



6
7
8
9
10
11
12
13
14
# File 'lib/youtube_it/parser.rb', line 6

def initialize(content)
  @content = (content =~ URI::regexp(%w(http https)) ? open(content).read : content)

rescue OpenURI::HTTPError => e
  raise OpenURI::HTTPError.new(e.io.status[0],e)
rescue
  @content = content

end

Instance Method Details

#parseObject



16
17
18
# File 'lib/youtube_it/parser.rb', line 16

def parse
  parse_content @content
end

#parse_single_entryObject



20
21
22
23
# File 'lib/youtube_it/parser.rb', line 20

def parse_single_entry
  doc = Nokogiri::XML(@content)
  parse_entry(doc.at("entry") || doc)
end

#parse_videosObject



25
26
27
28
29
30
31
32
# File 'lib/youtube_it/parser.rb', line 25

def parse_videos
  doc = Nokogiri::XML(@content)
  videos = []
  doc.css("entry").each do |video|
    videos << parse_entry(video)
  end
  videos
end

#remove_bom(str) ⇒ Object



34
35
36
# File 'lib/youtube_it/parser.rb', line 34

def remove_bom str
  str.gsub /\xEF\xBB\xBF|/, '' if str
end