Class: Hulu::Show
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#episodes ⇒ Object
Returns the value of attribute episodes.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#genre ⇒ Object
Returns the value of attribute genre.
-
#network ⇒ Object
Returns the value of attribute network.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #error_404? ⇒ Boolean
-
#initialize(title) ⇒ Show
constructor
A new instance of Show.
- #parse_episodes ⇒ Object
- #parse_show_details ⇒ Object
- #set_url ⇒ Object
- #to_param ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(title) ⇒ Show
Returns a new instance of Show.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hulu/show.rb', line 15 def initialize(title) @title = title @episodes = [] @doc = Hulu.query(@title) @errors = [] if error_404? @errors << "404: Show not found" return end parse_show_details parse_episodes set_url @doc = nil end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def description @description end |
#episodes ⇒ Object
Returns the value of attribute episodes.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def episodes @episodes end |
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def errors @errors end |
#genre ⇒ Object
Returns the value of attribute genre.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def genre @genre end |
#network ⇒ Object
Returns the value of attribute network.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def network @network end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/hulu/show.rb', line 7 def url @url end |
Instance Method Details
#error_404? ⇒ Boolean
37 38 39 40 |
# File 'lib/hulu/show.rb', line 37 def error_404? error = @doc.css('.fixed-lg .section .gr').text.strip rescue '' error =~ /404/ ? true : false end |
#parse_episodes ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hulu/show.rb', line 49 def parse_episodes episodes = @doc.css("#show-expander table") episodes.each_with_index do |episode, i| # There are several tables under the show-expander # we are only interested in the first break if i > 0 season = episode.css('tr.srh td').first.text.strip rescue '' episode.css('tr.r').each do |episode_info| @episodes << Hulu::Episode.new(@title) do |epi| epi.process(season, episode_info) end end end end |
#parse_show_details ⇒ Object
42 43 44 45 46 47 |
# File 'lib/hulu/show.rb', line 42 def parse_show_details details = @doc.css(".fixed-lg.container .section.details .relative .info") @network = details[0].text.strip rescue '' @genre = details[2].text.split('|').first.gsub(/\302\240/, ' ').strip rescue '' @description = details[3].text.strip rescue '' end |
#set_url ⇒ Object
33 34 35 |
# File 'lib/hulu/show.rb', line 33 def set_url @url = "#{Hulu::BASE_URI}/#{Hulu::Base.prepare_name(@title)}" end |
#to_param ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hulu/show.rb', line 66 def to_param { network: network, title: title, genre: genre, description: description, url: url, episodes: episodes.map { |e| e.to_param }, errors: errors } end |