Class: Schedule
- Inherits:
-
Object
- Object
- Schedule
- Includes:
- ShellColors, Timings
- Defined in:
- lib/bbc/schedule.rb
Overview
Shows schedule information for BBC Television and Radio stations
Helpful urls
www.bbc.co.uk/programmes/developers www.bbc.co.uk/ontologies/programmes/2009-09-07.shtml
Instance Method Summary collapse
-
#initialize(io = STDOUT) ⇒ Schedule
constructor
A new instance of Schedule.
- #list(data, period) ⇒ Object
- #load(channel) ⇒ Object
Methods included from ShellColors
blue, cyan, green, light_green, paint, red, white, yellow
Methods included from Timings
Constructor Details
#initialize(io = STDOUT) ⇒ Schedule
Returns a new instance of Schedule.
13 14 15 |
# File 'lib/bbc/schedule.rb', line 13 def initialize(io = STDOUT) @io = io end |
Instance Method Details
#list(data, period) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bbc/schedule.rb', line 29 def list(data, period) now = time_now data['schedule']['day']['broadcasts'].each do |e| ends = Time.parse(e['end']) next if ends < now unless period == '/yesterday' title = e['programme']['display_titles']['title'] # synopsis = e['programme']['short_synopsis'] starts = Time.parse(e['start']) starts_at = starts.strftime('%H:%M') # "%I:%M%P" desc = "#{starts_at} #{title}" on_now = (starts < now && ends > now) desc = light_green desc if on_now @io.puts desc end end |
#load(channel) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bbc/schedule.rb', line 17 def load(channel) station = channel[:id] region = channel[:region] ||= '' period = channel[:period] ||= '' url = "http://www.bbc.co.uk/#{station}/programmes/schedules#{region}#{period}.json" raw = open(url, 'UserAgent' => AUNTIE::USER_AGENT).read data = JSON.parse(raw) list data, period end |