pomato 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17278832c4649f44cb47123e74e7e4de1f78bcc2
4
- data.tar.gz: f4f01665a0e5c913a9ba7827f5f5d905890dfafe
3
+ metadata.gz: 7f8567836c7256df5d1ca371debd1e2e8b4ebd64
4
+ data.tar.gz: e8da4054f113faf46cb9ecdb13ce4dd26a12ad69
5
5
  SHA512:
6
- metadata.gz: 8c4fd1b30f0b5d40c8f3d0363a22e99a1e677b767a1c980ee76ba93f1b38656d3dfe9f1faa2d181e8a6b56bd78dccf8844e233492bfc64dcab2549a61434b15a
7
- data.tar.gz: f9f3f2fbbaa9db3ecf92fb76e7c1b9d305cbe264a4691c18a68eb24ac2002b256edb1677e9f298a369647d60a41a7c9d327c608d840c1b584abeab903af6b077
6
+ metadata.gz: 682497131a7402ce7ed3bef71c8955abae888938b6334bcdf1ecf62553273597e35c4913689f7e1b2f71168497c315eb01179d250168b5923a9f8560593fdda1
7
+ data.tar.gz: eb6ec5710e7a84b2686694dfc25707c794866a148b4692f5b17cc87ba17f74293ad052409b23c8d34be533fabb3220120705779f1425d650f687883b1336d28a
@@ -0,0 +1,64 @@
1
+ require 'securerandom'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+
5
+ module Pomato
6
+ module Paths
7
+ include FileUtils
8
+
9
+ attr_reader :args
10
+
11
+ def initialize(*args)
12
+ @args = args
13
+ end
14
+
15
+ def now
16
+ @now ||= Time.now.to_i
17
+ end
18
+
19
+ def play_alert
20
+ `afplay #{path_to('alert.mp3')}`
21
+ end
22
+
23
+ def history(message)
24
+ append_to history_path, "#{now} #{message}"
25
+ end
26
+
27
+ def history_path
28
+ File.join home, 'history'
29
+ end
30
+
31
+ def path_to(name)
32
+ File.expand_path(File.join(home, name))
33
+ end
34
+
35
+ def jobs
36
+ Dir["#{home('jobs')}/*"].map {|p| load_yaml(p).merge(id: p) }
37
+ end
38
+
39
+ def make_job(job)
40
+ dump_yaml(File.join(home('jobs'), SecureRandom.uuid), job)
41
+ end
42
+
43
+ def finish_job(job)
44
+ history "finish #{job[:time]} #{job[:name]}"
45
+ File.delete job[:id]
46
+ end
47
+
48
+ def home(*paths)
49
+ (File.join(File.expand_path('~'),'/.pomato',*paths)).tap {|path| mkdir_p path }
50
+ end
51
+
52
+ def append_to(path, content)
53
+ File.open(path, 'a') { |f| f.puts content }
54
+ end
55
+
56
+ def dump_yaml(path, data)
57
+ File.open(path, 'w') { |f| YAML.dump(data, f) }
58
+ end
59
+
60
+ def load_yaml(path)
61
+ File.exist?(path) ? YAML.load_file(path) : {}
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ require 'pomato/paths'
2
+
3
+ module Pomato
4
+ class Report
5
+ include Paths
6
+
7
+ def execute
8
+ jobs.each do |job|
9
+ duration = now - job[:start]
10
+ remaining = job[:time] - duration
11
+ puts "job #{job[:name]}: #{duration} (#{remaining} remaining)"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'pomato/paths'
2
+
3
+ module Pomato
4
+ class Start
5
+ include Paths
6
+
7
+ def execute
8
+ time = args.shift.to_i * 60
9
+ name = args.join(' ')
10
+ history "start #{time} #{name}"
11
+ make_job start: now, name: name, time: time
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'pomato/paths'
2
+
3
+ module Pomato
4
+ class Tick
5
+ include Paths
6
+
7
+ def execute
8
+ alert = false
9
+ jobs.each do |job|
10
+ if (job[:start] + job[:time]) < now
11
+ finish_job job
12
+ alert = true
13
+ end
14
+ end
15
+ play_alert if alert
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Pomato
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/pomato.rb CHANGED
@@ -1,14 +1,24 @@
1
- require 'pomato/version'
1
+ require 'pomato/tick'
2
+ require 'pomato/start'
3
+ require 'pomato/report'
2
4
 
3
5
  module Pomato
4
6
  module Cli
5
7
  def self.execute(*args)
6
8
  method, *args = args
7
- send method, *args
9
+ send (method || :report), *args
10
+ end
11
+
12
+ def self.report
13
+ Pomato::Report.new.execute
8
14
  end
9
15
 
10
16
  def self.tick(*args)
11
- puts ['tick', *args].join(' ')
17
+ Pomato::Tick.new(*args).execute
18
+ end
19
+
20
+ def self.start(*args)
21
+ Pomato::Start.new(*args).execute
12
22
  end
13
23
  end
14
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pomato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,6 +53,10 @@ files:
53
53
  - Rakefile
54
54
  - bin/pomato
55
55
  - lib/pomato.rb
56
+ - lib/pomato/paths.rb
57
+ - lib/pomato/report.rb
58
+ - lib/pomato/start.rb
59
+ - lib/pomato/tick.rb
56
60
  - lib/pomato/version.rb
57
61
  - pomato.gemspec
58
62
  homepage: http://github.com/markryall/pomatorb