Class: TimeUntilBreak

Inherits:
Object
  • Object
show all
Defined in:
lib/time_until_break.rb,
lib/time_until_break/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timeObject (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_timeObject



35
36
37
# File 'lib/time_until_break.rb', line 35

def current_time
  Time.now
end

#has_break_been?Boolean

Returns:

  • (Boolean)


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

def has_break_been?
  current_time > @break_time
end

#is_a_weekdayObject



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_weekendObject



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

Returns:

  • (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_breakObject



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

def missed_break
  say_something("Sorry you missed the Mandatory Break.")
end

#run_meObject



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_breakObject



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