class TivoHelper::Show

Attributes

genre[RW]
name[RW]
network[RW]
time[RW]

Public Class Methods

all() click to toggle source
# File lib/tivo_helper/show.rb, line 30
def self.all
  @@all
end
create_from_scraper(listing) click to toggle source

This works! Leave it alone!

# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/tivo_helper/show.rb, line 34
def self.genres
  @@genres.uniq
end
networks() click to toggle source
# File lib/tivo_helper/show.rb, line 38
def self.networks
  @@networks.uniq
end
new() click to toggle source
# File lib/tivo_helper/show.rb, line 7
def initialize
  @@all << self
end
sort_by_genre() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/tivo_helper/show.rb, line 42
def self.sort_by_time
  self.all
end

Public Instance Methods

find_by_name(name) click to toggle source
# File lib/tivo_helper/show.rb, line 46
def find_by_name(name)
  self.all.detect {|show| show.name == name}
end
genre=(genre) click to toggle source
# File lib/tivo_helper/show.rb, line 70
def genre=(genre)
  @genre = genre
  @@genres << genre
end
network=(network) click to toggle source
# File lib/tivo_helper/show.rb, line 75
def network=(network)
  @network = network
  @@networks << network
end