Class: TivoHelper::Show
- Inherits:
-
Object
- Object
- TivoHelper::Show
- Defined in:
- lib/tivo_helper/show.rb
Constant Summary collapse
- @@all =
[]
- @@genres =
[]
- @@networks =
[]
Instance Attribute Summary collapse
-
#genre ⇒ Object
Returns the value of attribute genre.
-
#name ⇒ Object
Returns the value of attribute name.
-
#network ⇒ Object
Returns the value of attribute network.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
- .all ⇒ Object
-
.create_from_scraper(listing) ⇒ Object
This works! Leave it alone!.
- .find_all_by_genre(genre) ⇒ Object
- .find_all_by_network(network) ⇒ Object
- .genres ⇒ Object
- .networks ⇒ Object
- .sort_by_genre ⇒ Object
- .sort_by_network ⇒ Object
- .sort_by_time ⇒ Object
Instance Method Summary collapse
- #find_by_name(name) ⇒ Object
-
#initialize ⇒ Show
constructor
A new instance of Show.
Constructor Details
#initialize ⇒ Show
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
#genre ⇒ Object
Returns the value of attribute genre.
2 3 4 |
# File 'lib/tivo_helper/show.rb', line 2 def genre @genre end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/tivo_helper/show.rb', line 2 def name @name end |
#network ⇒ Object
Returns the value of attribute network.
2 3 4 |
# File 'lib/tivo_helper/show.rb', line 2 def network @network end |
#time ⇒ Object
Returns the value of attribute time.
2 3 4 |
# File 'lib/tivo_helper/show.rb', line 2 def time @time end |
Class Method Details
.all ⇒ Object
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 |
.genres ⇒ Object
34 35 36 |
# File 'lib/tivo_helper/show.rb', line 34 def self.genres @@genres.uniq end |
.networks ⇒ Object
38 39 40 |
# File 'lib/tivo_helper/show.rb', line 38 def self.networks @@networks.uniq end |
.sort_by_genre ⇒ Object
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_network ⇒ Object
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_time ⇒ Object
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 |