Class: NetworkExecutive::Guide

Inherits:
Hash
  • Object
show all
Defined in:
app/models/network_executive/guide.rb

Overview

TODO: Why does this subclass Hash? TODO: This is an ugly data structure. Refactor.

Constant Summary collapse

Interval =

In minutes.

15
Range =

In hours.

1.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = nil, stop = nil) ⇒ Guide

Returns a new instance of Guide.



13
14
15
16
17
18
# File 'app/models/network_executive/guide.rb', line 13

def initialize( start = nil, stop = nil )
  self.start_time = start || Time.now
  self.stop_time  = stop  || Time.now + Range.hours

  self[:channels] = generate
end

Instance Attribute Details

#start_timeObject

Returns the value of attribute start_time.



11
12
13
# File 'app/models/network_executive/guide.rb', line 11

def start_time
  @start_time
end

#stop_timeObject

Returns the value of attribute stop_time.



11
12
13
# File 'app/models/network_executive/guide.rb', line 11

def stop_time
  @stop_time
end

Instance Method Details

#generateObject



20
21
22
23
24
25
26
27
28
29
# File 'app/models/network_executive/guide.rb', line 20

def generate
  with_each_channel do |channel, guide|
    programs = channel.whats_on_between? start_time, stop_time, Interval.minutes

    guide << {
      channel:  channel,
      programs: programs
    }
  end
end

#timesObject

TODO: Add test



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/network_executive/guide.rb', line 40

def times
  @times ||= begin
    cursor = start_time.dup

    times  = []

    while cursor < stop_time do
      times << cursor

      cursor += Interval.minutes
    end

    times
  end
end