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.


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

def initialize(schedule)
  @schedule = schedule
end

Class Method Details

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


13
14
15
16
17
18
19
20
21
# File 'lib/pomodoro/scheduler.rb', line 13

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, schedule: nil, apply_rules: [], remove_rules: []) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pomodoro/scheduler.rb', line 43

def populate_from_rules(task_list, schedule: nil, apply_rules: [], remove_rules: [])
  self.rules.each do |rule|
    if rule.true?(schedule)
      puts "~ Invoking rule <green>#{rule.name}</green>.".colourise
      rule.call(task_list)
    end
  end

  # Add #gen tag to all the generated tasks.
  task_list.each_task do |task|
    task.tags << :gen
  end
end

#rulesObject


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

def rules
  @schedule.rules
end

#schedule_for_date(date) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/pomodoro/scheduler.rb', line 35

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

  nil
end

#schedulesObject


31
32
33
# File 'lib/pomodoro/scheduler.rb', line 31

def schedules
  @schedule.schedules
end