Class: Hulu::Episode
Instance Attribute Summary collapse
-
#air_date ⇒ Object
Returns the value of attribute air_date.
-
#beaconid ⇒ Object
Returns the value of attribute beaconid.
-
#coming_soon ⇒ Object
Returns the value of attribute coming_soon.
-
#description ⇒ Object
Returns the value of attribute description.
-
#embed_html ⇒ Object
Returns the value of attribute embed_html.
-
#episode ⇒ Object
Returns the value of attribute episode.
-
#running_time ⇒ Object
Returns the value of attribute running_time.
-
#season ⇒ Object
Returns the value of attribute season.
-
#show_title ⇒ Object
Returns the value of attribute show_title.
-
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #additional_attributes ⇒ Object
- #fetch_description ⇒ Object
-
#initialize(show_title = '') {|_self| ... } ⇒ Episode
constructor
A new instance of Episode.
- #parse_coming_soon(episode) ⇒ Object
- #parse_coming_soon_date ⇒ Object
- #parse_running_time(episode) ⇒ Object
- #process(season, episode) ⇒ Object
- #set_additional_attributes ⇒ Object
- #to_param ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(show_title = '') {|_self| ... } ⇒ Episode
Returns a new instance of Episode.
15 16 17 18 19 20 21 22 |
# File 'lib/hulu/show/episode.rb', line 15 def initialize(show_title = '') self.show_title = show_title yield self if block_given? set_additional_attributes fetch_description end |
Instance Attribute Details
#air_date ⇒ Object
Returns the value of attribute air_date.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def air_date @air_date end |
#beaconid ⇒ Object
Returns the value of attribute beaconid.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def beaconid @beaconid end |
#coming_soon ⇒ Object
Returns the value of attribute coming_soon.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def coming_soon @coming_soon end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def description @description end |
#embed_html ⇒ Object
Returns the value of attribute embed_html.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def @embed_html end |
#episode ⇒ Object
Returns the value of attribute episode.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def episode @episode end |
#running_time ⇒ Object
Returns the value of attribute running_time.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def running_time @running_time end |
#season ⇒ Object
Returns the value of attribute season.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def season @season end |
#show_title ⇒ Object
Returns the value of attribute show_title.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def show_title @show_title end |
#thumbnail_url ⇒ Object
Returns the value of attribute thumbnail_url.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def thumbnail_url @thumbnail_url end |
#title ⇒ Object
Returns the value of attribute title.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/hulu/show/episode.rb', line 2 def url @url end |
Instance Method Details
#additional_attributes ⇒ Object
80 81 82 83 |
# File 'lib/hulu/show/episode.rb', line 80 def additional_attributes url = "http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/#{@beaconid}/#{Hulu::Base.prepare_name(@title)}" Hulu::Fetcher::Page.get(url).parsed_response end |
#fetch_description ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hulu/show/episode.rb', line 34 def fetch_description show_name = Hulu::Base.prepare_name(@show_title) title = Hulu::Base.prepare_name(@title) url = "http://www.hulu.com/watch/#{@beaconid}/#{show_name}-#{title}" info = Hulu::Fetcher::Page.get(url).parsed_response d = info.css('#description-contents').text.strip rescue '' @description = d.split('Hide Description').first if d end |
#parse_coming_soon(episode) ⇒ Object
68 69 70 71 |
# File 'lib/hulu/show/episode.rb', line 68 def parse_coming_soon(episode) cs = episode.css('td.c1 .vex-h a').first.css('img').attr('alt').value.strip rescue false cs ? true : false end |
#parse_coming_soon_date ⇒ Object
73 74 75 76 77 78 |
# File 'lib/hulu/show/episode.rb', line 73 def parse_coming_soon_date # In order to accomplish this, the episode will need access to # the entire html document # The following will get the available date on Hulu # ("#episode-container .coming-soon span").first.text end |
#parse_running_time(episode) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hulu/show/episode.rb', line 56 def parse_running_time(episode) run_time = episode.css('td.c3').text.strip if run_time.include?(':') @running_time = run_time @air_date = episode.css('td.c4').text.strip rescue '' else @running_time = episode.css('td.c4').text.strip rescue '' @air_date = episode.css('td.c5').text.strip rescue '' end end |
#process(season, episode) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hulu/show/episode.rb', line 45 def process(season, episode) @season = season.scan(/\d+/).first @episode = episode.css('td.c0').text.strip rescue '' @title = episode.css('td.c1 a').text.strip rescue '' @coming_soon = parse_coming_soon(episode) @url = episode.css('td.c1 .vex-h a').last.attr('href').strip rescue '' @beaconid = episode.css('td.c1 .vex-h a').last.attr('beaconid').strip rescue '' parse_running_time(episode) end |
#set_additional_attributes ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/hulu/show/episode.rb', line 24 def set_additional_attributes info = additional_attributes @embed_html = info['html'] @thumbnail_url = info['thumbnail_url'] if @air_date && @air_date.empty? @air_date = Date.parse(info['air_date']).strftime("%m-%d-%Y") end end |
#to_param ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/hulu/show/episode.rb', line 85 def to_param { show_title: show_title, title: title, episode: episode, running_time: running_time, air_date: air_date, season: season, url: url, beaconid: beaconid, thumbnail_url: thumbnail_url, embed_html: , description: description, coming_soon: coming_soon } end |