Class: Hulu::Show

Inherits:
Base
  • Object
show all
Defined in:
lib/hulu/show.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

prepare_name

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

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/hulu/show.rb', line 7

def description
  @description
end

#episodesObject

Returns the value of attribute episodes.



7
8
9
# File 'lib/hulu/show.rb', line 7

def episodes
  @episodes
end

#errorsObject

Returns the value of attribute errors.



7
8
9
# File 'lib/hulu/show.rb', line 7

def errors
  @errors
end

#genreObject

Returns the value of attribute genre.



7
8
9
# File 'lib/hulu/show.rb', line 7

def genre
  @genre
end

#networkObject

Returns the value of attribute network.



7
8
9
# File 'lib/hulu/show.rb', line 7

def network
  @network
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/hulu/show.rb', line 7

def title
  @title
end

#urlObject

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

Returns:

  • (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_episodesObject



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_detailsObject



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_urlObject



33
34
35
# File 'lib/hulu/show.rb', line 33

def set_url
  @url = "#{Hulu::BASE_URI}/#{Hulu::Base.prepare_name(@title)}"
end

#to_paramObject



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