Created
July 23, 2010 11:34
-
-
Save mkroman/487319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'date' | |
module DR | |
class TV | |
attr_reader :channels | |
def initialize options = {} | |
@client = DR::Client.new | |
@channels = @client.channels | |
# get schedules for all channels | |
if options[:update_schedules] | |
update_schedules | |
end | |
end | |
def channel name | |
@channels.select{ |c| c.name == name }.first | |
end | |
# Add a schedule to a channel, e.g. tomorrow. | |
# EXAMPLE: add_schedule channel("DR1"), DateTime.now + 1 | |
def add_schedule channel, date = nil | |
schedule = @client.schedule channel, date | |
schedule.each { |program| channel.add program } | |
end | |
# Update the schedule of a single channel. | |
def update channel, date = nil | |
channel.clear | |
schedule = @client.schedule channel, date | |
schedule.each { |program| channel.add program } | |
end | |
# update all channels | |
def update_schedules | |
@channels.each { |channel| channel.clear } | |
debug "Updating schedules…" | |
buffer = @channels.dup | |
until buffer.empty? | |
@client.schedules(buffer[0..4]).each do |channel, schedule| | |
schedule.each { |program| channel.add program } | |
end | |
buffer.slice! 0..4 | |
end | |
debug "Updating complete…" | |
end | |
# Search all channels for the program(s) which matches /<program_title>/ | |
def program_search program_title, program_description | |
@channels.map{ |c| c.search program_title, program_description }.flatten | |
end | |
# program_search as a block!!!!11111111111 | |
def find program_title, program_description = nil, &block | |
program_search(program_title, program_description).each do |program| | |
yield program | |
end | |
end | |
private | |
# denne metode er kun midlertidig | |
def debug string | |
puts ">> #{string}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment