Module: Tmuxodoro

Defined in:
lib/tmuxodoro.rb,
lib/tmuxodoro/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.run(port, args = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tmuxodoro.rb', line 7

def run(port, args = {})
  pomodoro = Pomodoro.new(args)
  server = WEBrick::HTTPServer.new(Port: port)

  server.mount_proc('/') do |req, resp|
    resp['Content-Type'] = 'text/plain'
    resp.body = pomodoro.status
  end

  server.mount_proc('/start') do |req, resp|
    pomodoro.start
    resp['Content-Type'] = 'text/plain'
    resp.body = "New tomato has been started, it ends at #{pomodoro.stop_at}.\n"
  end

  server.mount_proc('/restart') do |req, resp|
    pomodoro = Pomodoro.new(args)
    resp['Content-Type'] = 'text/plain'
    resp.body = "Tomatos have been reset\n"
  end

  server.start
end