Class: Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/yuris-timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Timer

Returns a new instance of Timer.



4
5
6
7
# File 'lib/yuris-timer.rb', line 4

def initialize(args)
  @number_of_minutes, *@message = *args
  @message = @message.join(" ")
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



2
3
4
# File 'lib/yuris-timer.rb', line 2

def message
  @message
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
# File 'lib/yuris-timer.rb', line 17

def start
  pid = fork do
    sleep(total_seconds)
    `terminal-notifier -title "#{title}" -message "#{message}"`
  end
  
  Process.detach(pid)
end

#titleObject



9
10
11
# File 'lib/yuris-timer.rb', line 9

def title
  "#{@number_of_minutes.to_i} min timer elapsed"
end

#total_secondsObject



26
27
28
# File 'lib/yuris-timer.rb', line 26

def total_seconds
  (@number_of_minutes.to_f * 60).to_i
end