Class: FileScheduler::Scheduling

Inherits:
Object
  • Object
show all
Defined in:
lib/file_scheduler/scheduling.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, time) ⇒ Scheduling

Returns a new instance of Scheduling.



6
7
8
9
# File 'lib/file_scheduler/scheduling.rb', line 6

def initialize(root, time)
  @root = root
  @time = time
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



4
5
6
# File 'lib/file_scheduler/scheduling.rb', line 4

def log
  @log
end

#rootObject

Returns the value of attribute root.



4
5
6
# File 'lib/file_scheduler/scheduling.rb', line 4

def root
  @root
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'lib/file_scheduler/scheduling.rb', line 4

def time
  @time
end

Instance Method Details

#forced_contentsObject



37
38
39
# File 'lib/file_scheduler/scheduling.rb', line 37

def forced_contents
  schedulable_contents.select &:forced_started_time?
end

#forced_nextObject



41
42
43
# File 'lib/file_scheduler/scheduling.rb', line 41

def forced_next
  forced_contents.first
end

#next_with_logObject Also known as: next



53
54
55
# File 'lib/file_scheduler/scheduling.rb', line 53

def next_with_log
  log.log(next_without_log)
end

#next_without_logObject



49
50
51
# File 'lib/file_scheduler/scheduling.rb', line 49

def next_without_log
  forced_next or schedulable_next
end

#schedulable?(content) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/file_scheduler/scheduling.rb', line 15

def schedulable?(content)
  schedulable_by_time?(content) and 
    schedulable_by_repeat?(content)
end

#schedulable_by_repeat?(content) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/file_scheduler/scheduling.rb', line 25

def schedulable_by_repeat?(content)
  content.repeat_constraints.nil? or
    log.distance(content).nil? or
    log.distance(content) >= content.repeat_constraints
end

#schedulable_by_time?(content) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/file_scheduler/scheduling.rb', line 20

def schedulable_by_time?(content)
  content.time_constraints.nil? or
    content.time_constraints.matches?(time)
end

#schedulable_contentsObject



31
32
33
34
35
# File 'lib/file_scheduler/scheduling.rb', line 31

def schedulable_contents
  @schedulable_contents ||= root.contents.select do |content|
    schedulable? content
  end
end

#schedulable_nextObject



45
46
47
# File 'lib/file_scheduler/scheduling.rb', line 45

def schedulable_next
  schedulable_contents.shuffle.first
end