Class: Pomodoro::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro/scheduler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schedule) ⇒ Scheduler

Returns a new instance of Scheduler.



20
21
22
# File 'lib/pomodoro/scheduler.rb', line 20

def initialize(schedule)
  @schedule = schedule
end

Class Method Details

.load(paths, today = Date.today) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/pomodoro/scheduler.rb', line 10

def self.load(paths, today = Date.today)
  dir = File.expand_path("#{paths.first}/..") # HACK This way we don't have to merge multiple contexts or reset its path.
  context = Pomodoro::Schedule::DSL.new(dir, today)
  paths.each do |path|
    context.instance_eval(File.read(path), path)
  end

  self.new(context)
end

Instance Method Details

#populate_from_rules(task_list) ⇒ Object



40
41
42
43
44
# File 'lib/pomodoro/scheduler.rb', line 40

def populate_from_rules(task_list)
  self.rules.each do |rule_name, rule|
    rule.true? && rule.call(task_list)
  end
end

#rulesObject



24
25
26
# File 'lib/pomodoro/scheduler.rb', line 24

def rules
  @schedule.rules
end

#schedule_for_date(date) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/pomodoro/scheduler.rb', line 32

def schedule_for_date(date)
  self.schedules.each do |name, schedule|
    return schedule if schedule.true?
  end

  return nil
end

#schedulesObject



28
29
30
# File 'lib/pomodoro/scheduler.rb', line 28

def schedules
  @schedule.schedules
end