Class: TivoHelper::Show

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

Constant Summary collapse

@@all =
[]
@@genres =
[]
@@networks =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShow

Returns a new instance of Show.



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

def initialize
  @@all << self
end

Instance Attribute Details

#genreObject

Returns the value of attribute genre.



2
3
4
# File 'lib/tivo_helper/show.rb', line 2

def genre
  @genre
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/tivo_helper/show.rb', line 2

def name
  @name
end

#networkObject

Returns the value of attribute network.



2
3
4
# File 'lib/tivo_helper/show.rb', line 2

def network
  @network
end

#timeObject

Returns the value of attribute time.



2
3
4
# File 'lib/tivo_helper/show.rb', line 2

def time
  @time
end

Class Method Details

.allObject



30
31
32
# File 'lib/tivo_helper/show.rb', line 30

def self.all
  @@all
end

.create_from_scraper(listing) ⇒ Object

This works! Leave it alone!



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tivo_helper/show.rb', line 12

def self.create_from_scraper(listing)
  this_name = listing.css(".title").text.strip
  this_genre = listing.css(".title + td").text.strip
  this_time = listing.css("td:last-of-type").text.strip
  if !this_time.match(/^\d/) && this_time
    modified_time = this_time.split(", ")
    this_time = modified_time[1]
    this_network = modified_time[0]
  else
    this_network = listing.css("td:last-of-type img").attribute("alt").value
  end
  new_show = TivoHelper::Show.new
  new_show.name = this_name
  new_show.genre = this_genre
  new_show.time = this_time
  new_show.network = (this_network || "Netflix")
end

.find_all_by_genre(genre) ⇒ Object



50
51
52
# File 'lib/tivo_helper/show.rb', line 50

def self.find_all_by_genre(genre)
  self.all.find_all {|show| show.genre == genre}
end

.find_all_by_network(network) ⇒ Object



54
55
56
# File 'lib/tivo_helper/show.rb', line 54

def self.find_all_by_network(network)
  self.all.find_all {|show| show.network == network}
end

.genresObject



34
35
36
# File 'lib/tivo_helper/show.rb', line 34

def self.genres
  @@genres.uniq
end

.networksObject



38
39
40
# File 'lib/tivo_helper/show.rb', line 38

def self.networks
  @@networks.uniq
end

.sort_by_genreObject



58
59
60
61
62
# File 'lib/tivo_helper/show.rb', line 58

def self.sort_by_genre
  self.genres.each do |genre|
    self.find_all_by_genre(genre)
  end
end

.sort_by_networkObject



64
65
66
67
68
# File 'lib/tivo_helper/show.rb', line 64

def self.sort_by_network
  self.networks.each do |genre|
    self.find_all_by_genre(genre)
  end
end

.sort_by_timeObject



42
43
44
# File 'lib/tivo_helper/show.rb', line 42

def self.sort_by_time
  self.all
end

Instance Method Details

#find_by_name(name) ⇒ Object



46
47
48
# File 'lib/tivo_helper/show.rb', line 46

def find_by_name(name)
  self.all.detect {|show| show.name == name}
end