Class: Domodoro::Schedule
- Inherits:
-
Object
- Object
- Domodoro::Schedule
- Defined in:
- lib/domodoro/schedule.rb
Instance Method Summary collapse
- #action_after(timestamp) ⇒ Object
- #current_action(timestamp) ⇒ Object
- #generate! ⇒ Object
-
#initialize ⇒ Schedule
constructor
A new instance of Schedule.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Schedule
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() times = @times.dup times[] ||= :now sorted = times.sort idx = sorted.index do |element| element == sorted.assoc() 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() times = @times.dup if times[] minus_one = false else minus_one = true times[] = :now end sorted = times.sort idx = sorted.index do |element| element == sorted.assoc() 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_hash ⇒ Object
19 20 21 |
# File 'lib/domodoro/schedule.rb', line 19 def to_hash @times end |