Class: Sleep
- Inherits:
-
Object
- Object
- Sleep
- Defined in:
- lib/sleep.rb
Overview
Sleep - A basic sleep-cycle calculator to get sleep cycle time for wake time or bed time.
Example:
require 'sleep'
sleep = Sleep.new
p sleep.now
#=> [...]
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#sleep_cycle ⇒ Object
Returns the value of attribute sleep_cycle.
-
#sleep_delay ⇒ Object
Returns the value of attribute sleep_delay.
Instance Method Summary collapse
-
#initialize ⇒ Sleep
constructor
A new instance of Sleep.
- #next(time) ⇒ Object
- #now ⇒ Object
- #previous(time) ⇒ Object
- #sleep_at(time) ⇒ Object
- #wakeup_at(time) ⇒ Object
Constructor Details
#initialize ⇒ Sleep
Returns a new instance of Sleep.
18 19 20 21 22 |
# File 'lib/sleep.rb', line 18 def initialize @delay = false @sleep_delay = 14 # average sleep delay minutes @sleep_cycle = 90 # sleep cycle minutes end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
16 17 18 |
# File 'lib/sleep.rb', line 16 def delay @delay end |
#sleep_cycle ⇒ Object
Returns the value of attribute sleep_cycle.
16 17 18 |
# File 'lib/sleep.rb', line 16 def sleep_cycle @sleep_cycle end |
#sleep_delay ⇒ Object
Returns the value of attribute sleep_delay.
16 17 18 |
# File 'lib/sleep.rb', line 16 def sleep_delay @sleep_delay end |
Instance Method Details
#next(time) ⇒ Object
38 39 40 41 |
# File 'lib/sleep.rb', line 38 def next(time) time = time.is_a?(String) ? Chronic.parse(time) : time next_cycle(time).strftime("%l:%M %p") end |
#now ⇒ Object
24 25 26 |
# File 'lib/sleep.rb', line 24 def now sleep_cycles(Time.now) end |
#previous(time) ⇒ Object
43 44 45 46 |
# File 'lib/sleep.rb', line 43 def previous(time) time = time.is_a?(String) ? Chronic.parse(time) : time prev_cycle(time).strftime("%l:%M %p") end |
#sleep_at(time) ⇒ Object
28 29 30 31 |
# File 'lib/sleep.rb', line 28 def sleep_at(time) time = Chronic.parse(time) sleep_cycles(time) end |
#wakeup_at(time) ⇒ Object
33 34 35 36 |
# File 'lib/sleep.rb', line 33 def wakeup_at(time) time = Chronic.parse(time) sleep_cycles(time, true) end |