pomato 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f8567836c7256df5d1ca371debd1e2e8b4ebd64
4
- data.tar.gz: e8da4054f113faf46cb9ecdb13ce4dd26a12ad69
3
+ metadata.gz: 1809867009864c93d7006f1e5a7824f7c47000b1
4
+ data.tar.gz: df303a5d703d86f3094fba112baa67de4b94ab6b
5
5
  SHA512:
6
- metadata.gz: 682497131a7402ce7ed3bef71c8955abae888938b6334bcdf1ecf62553273597e35c4913689f7e1b2f71168497c315eb01179d250168b5923a9f8560593fdda1
7
- data.tar.gz: eb6ec5710e7a84b2686694dfc25707c794866a148b4692f5b17cc87ba17f74293ad052409b23c8d34be533fabb3220120705779f1425d650f687883b1336d28a
6
+ metadata.gz: bddd7124c363561fff104a68a1d2ae0c2090915146b8f0ca1ca1f95941579441833c840b75bd75d93505d5ee317979552f2190f3eecfb1f9dafe0d364338a94f
7
+ data.tar.gz: 9362cbc77726ab8c1acf348213a617b8ee2a21ff35fac464b89c3658d9c7d9fe0a02da57f01339197a93e99bfc4d6b530c9dc3d4acda2691aef768adf4e86d7b
data/lib/pomato.rb CHANGED
@@ -1,24 +1,18 @@
1
- require 'pomato/tick'
2
- require 'pomato/start'
3
- require 'pomato/report'
4
-
5
1
  module Pomato
6
2
  module Cli
7
3
  def self.execute(*args)
8
4
  method, *args = args
9
- send (method || :report), *args
10
- end
11
-
12
- def self.report
13
- Pomato::Report.new.execute
5
+ method ||= :report
6
+ page_class(method).new(*args).execute
14
7
  end
15
8
 
16
- def self.tick(*args)
17
- Pomato::Tick.new(*args).execute
9
+ def self.classify(string)
10
+ string.to_s.split('_').map(&:capitalize).join
18
11
  end
19
12
 
20
- def self.start(*args)
21
- Pomato::Start.new(*args).execute
13
+ def self.page_class(name)
14
+ require "pomato/#{name}"
15
+ Pomato.const_get classify name
22
16
  end
23
17
  end
24
18
  end
@@ -0,0 +1,13 @@
1
+ require 'pomato/paths'
2
+
3
+ module Pomato
4
+ class History
5
+ include Paths
6
+
7
+ def execute
8
+ history_items.each do |item|
9
+ puts item
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/pomato/paths.rb CHANGED
@@ -24,6 +24,10 @@ module Pomato
24
24
  append_to history_path, "#{now} #{message}"
25
25
  end
26
26
 
27
+ def history_items
28
+ File.exist?(history_path) ? File.readlines(history_path) : []
29
+ end
30
+
27
31
  def history_path
28
32
  File.join home, 'history'
29
33
  end
@@ -33,16 +37,31 @@ module Pomato
33
37
  end
34
38
 
35
39
  def jobs
36
- Dir["#{home('jobs')}/*"].map {|p| load_yaml(p).merge(id: p) }
40
+ Dir["#{home('jobs')}/*"].map {|p| load_yaml(p) }
41
+ end
42
+
43
+ def dump_job(job)
44
+ dump_yaml(File.join(home('jobs'), job[:id]), job)
37
45
  end
38
46
 
39
- def make_job(job)
40
- dump_yaml(File.join(home('jobs'), SecureRandom.uuid), job)
47
+ def start_job(job)
48
+ job[:id] = SecureRandom.uuid
49
+ history "#{job[:id]} start #{job[:time]} #{job[:name]}"
50
+ dump_job job.merge(start: now)
51
+ end
52
+
53
+ def stop_job(job)
54
+ history "#{job[:id]} stop #{job[:time]} #{job[:name]}"
55
+ destroy_job job
41
56
  end
42
57
 
43
58
  def finish_job(job)
44
- history "finish #{job[:time]} #{job[:name]}"
45
- File.delete job[:id]
59
+ history "#{job[:id]} finish #{job[:time]} #{job[:name]}"
60
+ destroy_job job
61
+ end
62
+
63
+ def destroy_job(job)
64
+ File.delete File.join(home('jobs'), job[:id])
46
65
  end
47
66
 
48
67
  def home(*paths)
data/lib/pomato/report.rb CHANGED
@@ -5,11 +5,21 @@ module Pomato
5
5
  include Paths
6
6
 
7
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)"
8
+ jobs.sort_by! {|j| now + j[:time]}.each do |job|
9
+ elapsed = now - job[:start]
10
+ remaining = job[:time] - elapsed
11
+ end_time = now + job[:time]
12
+ puts " #{time_format end_time} (#{min_sec elapsed} completed, #{min_sec remaining} of #{min_sec job[:time]} remaining): #{job[:name]}"
12
13
  end
13
14
  end
15
+
16
+ def time_format(seconds)
17
+ time = Time.at seconds
18
+ time.strftime '%I:%M%p'
19
+ end
20
+
21
+ def min_sec(seconds)
22
+ "%02d:%02d" % [seconds/60, seconds%60]
23
+ end
14
24
  end
15
25
  end
data/lib/pomato/start.rb CHANGED
@@ -7,8 +7,7 @@ module Pomato
7
7
  def execute
8
8
  time = args.shift.to_i * 60
9
9
  name = args.join(' ')
10
- history "start #{time} #{name}"
11
- make_job start: now, name: name, time: time
10
+ start_job name: name, time: time
12
11
  end
13
12
  end
14
13
  end
@@ -0,0 +1,17 @@
1
+ require 'pomato/paths'
2
+
3
+ module Pomato
4
+ class Stop
5
+ include Paths
6
+
7
+ def execute
8
+ search_string = args.first
9
+ jobs.each do |job|
10
+ if job[:name].include? search_string
11
+ puts "stopping \"#{job[:name]}\""
12
+ stop_job job
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Pomato
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pomato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -53,9 +53,11 @@ files:
53
53
  - Rakefile
54
54
  - bin/pomato
55
55
  - lib/pomato.rb
56
+ - lib/pomato/history.rb
56
57
  - lib/pomato/paths.rb
57
58
  - lib/pomato/report.rb
58
59
  - lib/pomato/start.rb
60
+ - lib/pomato/stop.rb
59
61
  - lib/pomato/tick.rb
60
62
  - lib/pomato/version.rb
61
63
  - pomato.gemspec