Class: Epguides::Show

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Show

Returns a new instance of Show.



11
12
13
14
# File 'lib/epguides/show.rb', line 11

def initialize(args={})
  @slug = args[:slug]
  @url  = args[:url]
end

Instance Attribute Details

#slugObject (readonly)

Returns the value of attribute slug.



9
10
11
# File 'lib/epguides/show.rb', line 9

def slug
  @slug
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/epguides/show.rb', line 9

def url
  @url
end

Class Method Details

.search(q) ⇒ Object



46
47
48
49
50
51
# File 'lib/epguides/show.rb', line 46

def self.search(q)
  search_url = 'http://ajax.googleapis.com/ajax/services/search/web' +
    '?v=1.0&q=allintitle: site:epguides.com '
  results = JSON.parse RestClient.get(URI.escape(search_url + q))
  new url: results['responseData']['results'].first['url']
end

Instance Method Details

#episodesObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/epguides/show.rb', line 16

def episodes
  return @episodes if @episodes
  @episodes = EpisodeList.new
  parse_table.each do |row|
    if m = Episode::REGX.match(row)
      @episodes << Episode.new(m[2], m[3], m[4], m[5], m[6])
    end
  end
  @episodes
end

#nameObject



27
28
29
# File 'lib/epguides/show.rb', line 27

def name
  doc.css('//h1').text
end

#season(n) ⇒ Object



31
32
33
# File 'lib/epguides/show.rb', line 31

def season(n)
  Season.new(n.to_s, episodes.find_by_season(n))
end

#seasonsObject



35
36
37
38
39
40
# File 'lib/epguides/show.rb', line 35

def seasons
  pattern = Regexp.new("•\\s+Season\\s+(\\d+)")
  list.scan(pattern).map do |s|
    Season.new(self, s.first)
  end
end