Class: Domodoro::Schedule

Inherits:
Object
  • Object
show all
Defined in:
lib/domodoro/schedule.rb

Instance Method Summary collapse

Constructor Details

#initializeSchedule

Returns a new instance of Schedule.



3
4
5
6
# File 'lib/domodoro/schedule.rb', line 3

def initialize
  @times = {}
  @config = Config.get_server_configuration
end

Instance Method Details

#action_after(timestamp) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/domodoro/schedule.rb', line 44

def action_after(timestamp)
  times = @times.dup
  times[timestamp] ||= :now
  sorted = times.sort

  idx = sorted.index do |element|
    element == sorted.assoc(timestamp)
  end

  sorted[idx + 1]
end

#current_action(timestamp) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/domodoro/schedule.rb', line 23

def current_action(timestamp)
  times = @times.dup

  if times[timestamp]
    minus_one = false
  else
    minus_one = true
    times[timestamp] = :now
  end

  sorted = times.sort

  idx = sorted.index do |element|
    element == sorted.assoc(timestamp)
  end

  idx = idx - 1 if minus_one

  sorted[idx]
end

#generate!Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/domodoro/schedule.rb', line 8

def generate!
  # Key points
  @times[@config.lunch_time.to_s] = :lunch
  @times[@config.day_end.to_s] = :go_home



  generate_pomodoros_between(@config.day_start, @config.lunch_time)
  generate_pomodoros_between(@config.lunch_time + @config.lunch_duration, @config.day_end)
end

#to_hashObject



19
20
21
# File 'lib/domodoro/schedule.rb', line 19

def to_hash
  @times
end