Class: Guide
Instance Attribute Summary collapse
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#schedule ⇒ Object
Returns the value of attribute schedule.
Instance Method Summary collapse
- #current_program_on_channel(tms_guide_id) ⇒ Object
- #fake_it ⇒ Object
-
#initialize(logger) ⇒ Guide
constructor
A new instance of Guide.
-
#process_programs(jsonString) ⇒ Object
TODO: store as flat or nested?.
- #programs_on_channel ⇒ Object
- #walk_guide ⇒ Object
Constructor Details
#initialize(logger) ⇒ Guide
Returns a new instance of Guide.
7 8 9 10 11 12 |
# File 'lib/data_services/guide.rb', line 7 def initialize(logger) @logger = logger @channels = {} @schedule = [] end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
6 7 8 |
# File 'lib/data_services/guide.rb', line 6 def channels @channels end |
#schedule ⇒ Object
Returns the value of attribute schedule.
6 7 8 |
# File 'lib/data_services/guide.rb', line 6 def schedule @schedule end |
Instance Method Details
#current_program_on_channel(tms_guide_id) ⇒ Object
80 81 82 83 |
# File 'lib/data_services/guide.rb', line 80 def current_program_on_channel tms_guide_id now = Time.now @schedule.select { |s| s.tms_guide_id == tms_guide_id && s.start_time < now && s.end_time > now}.first end |
#fake_it ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/data_services/guide.rb', line 15 def fake_it t = Time.now p = Program.new(@logger) p.start_time = t -100 p.end_time = t + 1800 p.tms_guide_id = 59373 p.title = "Sinister 2" p.short_desc = "A woman and her sons encounter the evil spirit of Bughuul." @schedule.push p p3 = Program.new(@logger) p3.start_time = t -100 p3.end_time = t + 1700 p3.tms_guide_id = 58646 p3.title = "At This Hour with Berman and Bolduan" p3.short_desc = nil @schedule.push p3 p1 = Program.new(@logger) p1.start_time = t + 1801 p1.end_time = t + 3000 p1.tms_guide_id = 59373 p1.title = "A Little Chaos" p1.short_desc = "A widow becomes a gardener at Louis XIV's Versailles." @schedule.push p1 p4 = Program.new(@logger) p4.start_time = t + 1701 p4.end_time = t + 3600 p4.tms_guide_id = 58646 p4.title = "CNN Newsroom With Brianna Keilar" p4.short_desc = nil @schedule.push p4 p2 = Program.new(@logger) p2.start_time = t + 3001 p2.end_time = t + 5400 p2.tms_guide_id = 59373 p2.title = "Evan Almighty" p2.short_desc = "God commands a former newscaster to build an ark." @schedule.push p2 p5 = Program.new(@logger) p5.start_time = t + 3601 p5.end_time = t + 5400 p5.tms_guide_id = 58646 p5.title = "Wolf" p5.short_desc = nil @schedule.push p5 end |
#process_programs(jsonString) ⇒ Object
TODO: store as flat or nested?
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/data_services/guide.rb', line 87 def process_programs jsonString programs_hashmap = JSON.parse(jsonString) programs_hashmap.each do |tmsid| program_array = tmsid[1] # puts "Processing " + program_array.length.to_s + " programs" program_array.each do |program_hashmap| # puts program_hashmap program = Program.new(@logger) program.populate program_hashmap @schedule.push program end end end |
#programs_on_channel ⇒ Object
76 77 78 |
# File 'lib/data_services/guide.rb', line 76 def programs_on_channel @schedule.group_by(&:tms_guide_id) end |
#walk_guide ⇒ Object
69 70 71 72 73 74 |
# File 'lib/data_services/guide.rb', line 69 def walk_guide @schedule.each do |p| # @logger.info( "#{p.tms_guide_id} #{p.title}") puts( "#{p.tms_guide_id} #{p.title} S #{p.season} E #{p.episode} #{p.episode_title}") end end |