Class: SimplePvr::RecordingPlanner

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_pvr/recording_planner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRecordingPlanner

Returns a new instance of RecordingPlanner.



9
10
11
# File 'lib/simple_pvr/recording_planner.rb', line 9

def initialize
  @recordings = []
end

Class Method Details

.reloadObject



3
4
5
6
7
# File 'lib/simple_pvr/recording_planner.rb', line 3

def self.reload
  planner = self.new
  planner.read
  Model::Schedule.cleanup
end

Instance Method Details

#readObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/simple_pvr/recording_planner.rb', line 13

def read
  schedules = Model::Schedule.all
  specifications = schedules.find_all {|s| s.type == :specification }
  exceptions = schedules.find_all {|s| s.type == :exception }
  
  specifications.each do |specification|
    programmes = programmes_matching(specification)

    adjust_end_time_of_specification(specification, programmes)
    adjust_end_time_of_exceptions(specification, programmes, exceptions)

    programmes_with_exceptions_removed = programmes.find_all {|programme| !matches_exception(programme, exceptions) }
    programmes_filtered_by_weekdays = programmes_with_exceptions_removed.find_all {|programme| on_allowed_weekday(programme, specification) }
    programmes_filtered_by_time_of_day = programmes_filtered_by_weekdays.find_all {|programme| at_allowed_time_of_day(programme, specification) }

    add_programmes(specification, programmes_filtered_by_time_of_day)
  end

  PvrInitializer.scheduler.recordings = @recordings
end