Class: TimeUntilBreak
- Inherits:
-
Object
- Object
- TimeUntilBreak
- Defined in:
- lib/time_until_break.rb,
lib/time_until_break/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#break_time ⇒ Object
readonly
Returns the value of attribute break_time.
Instance Method Summary collapse
- #current_time ⇒ Object
- #has_break_been? ⇒ Boolean
-
#initialize(break_time = "16:45") ⇒ TimeUntilBreak
constructor
A new instance of TimeUntilBreak.
- #is_a_weekday ⇒ Object
- #is_a_weekend ⇒ Object
- #is_it_the_weekend? ⇒ Boolean
- #missed_break ⇒ Object
- #run_me ⇒ Object
- #say_something(string) ⇒ Object
- #time_until_break ⇒ Object
Constructor Details
#initialize(break_time = "16:45") ⇒ TimeUntilBreak
Returns a new instance of TimeUntilBreak.
8 9 10 |
# File 'lib/time_until_break.rb', line 8 def initialize (break_time="16:45") @break_time = Time.parse(break_time) end |
Instance Attribute Details
#break_time ⇒ Object (readonly)
Returns the value of attribute break_time.
6 7 8 |
# File 'lib/time_until_break.rb', line 6 def break_time @break_time end |
Instance Method Details
#current_time ⇒ Object
35 36 37 |
# File 'lib/time_until_break.rb', line 35 def current_time Time.now end |
#has_break_been? ⇒ Boolean
27 28 29 |
# File 'lib/time_until_break.rb', line 27 def has_break_been? current_time > @break_time end |
#is_a_weekday ⇒ Object
12 13 14 |
# File 'lib/time_until_break.rb', line 12 def is_a_weekday has_break_been? ? missed_break : time_until_break end |
#is_a_weekend ⇒ Object
16 17 18 |
# File 'lib/time_until_break.rb', line 16 def is_a_weekend say_something("It's the weekend you silly billy.") end |
#is_it_the_weekend? ⇒ Boolean
43 44 45 |
# File 'lib/time_until_break.rb', line 43 def is_it_the_weekend? ["Saturday", "Sunday"].include?(current_time.strftime("%A")) end |
#missed_break ⇒ Object
31 32 33 |
# File 'lib/time_until_break.rb', line 31 def missed_break say_something("Sorry you missed the Mandatory Break.") end |
#run_me ⇒ Object
47 48 49 |
# File 'lib/time_until_break.rb', line 47 def run_me is_it_the_weekend? ? is_a_weekend : is_a_weekday end |
#say_something(string) ⇒ Object
39 40 41 |
# File 'lib/time_until_break.rb', line 39 def say_something(string) %x(say "#{string}") end |
#time_until_break ⇒ Object
20 21 22 23 24 25 |
# File 'lib/time_until_break.rb', line 20 def time_until_break seconds = @break_time.to_i - current_time.to_i hours = (seconds/(60*60)) minutes = ((seconds - (hours*60*60))/60) say_something("#{hours} hours, #{minutes} minutes until the Mandatory Break.") end |