timekeeper 0.2.0 → 0.2.1

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.
@@ -1,8 +1,12 @@
1
1
  module Timekeeper
2
2
 
3
3
  class Keep
4
+
5
+ FIELDS = %w(pk name target title date time description tracked)
4
6
 
5
- attr_accessor :name, :time, :title, :description, :target, :date, :pk
7
+ FIELDS.each do |field|
8
+ attr_accessor field
9
+ end
6
10
 
7
11
  def initialize(attributes)
8
12
  set_attributes(attributes)
@@ -28,11 +32,15 @@ module Timekeeper
28
32
 
29
33
  def to_hash
30
34
  {:name => name, :time => time, :title => title, :description => description,
31
- :target => target, :date => date}
35
+ :target => target, :date => date, :tracked => tracked}
36
+ end
37
+
38
+ def values
39
+ [pk, name, target, title, date, time, description, tracked]
32
40
  end
33
41
 
34
42
  def to_s
35
- "#{pk}|#{name}|#{target}|#{title}|#{description}|#{date}|#{time}"
43
+ "#{pk}|#{name}|#{target}|#{title}|#{description}|#{date}|#{time}|#{tracked}"
36
44
  end
37
45
 
38
46
  private
@@ -23,8 +23,8 @@ module Timekeeper
23
23
  end
24
24
 
25
25
  def store(attributes)
26
- attributes.store("name", config["name"])
27
- attributes.store("date", Date.today) unless attributes["date"]
26
+ attributes.store(:name, config["name"])
27
+ attributes.store(:date, Date.today) unless attributes["date"]
28
28
  table[table.genuid] = Keep.new(attributes).to_hash
29
29
  end
30
30
 
@@ -40,6 +40,12 @@ module Timekeeper
40
40
  end
41
41
  end
42
42
 
43
+ def track(id, name)
44
+ tracking_table = Rufus::Tokyo::Table.new(File.join(config["db_path"],"tracking-time.tct"))
45
+ tracking_table[tracking_table.genuid] = {:keep_id => id, :name => name}
46
+ tracking_table.close
47
+ end
48
+
43
49
  private
44
50
 
45
51
  def table
@@ -12,6 +12,10 @@ module Timekeeper
12
12
  o.on("--config FILE", "location of your configuration file - default is ./timekeeper.yml") do |file|
13
13
  self[:config] = file
14
14
  end
15
+
16
+ o.on('-n', '--name NAME', 'Who did it?') do |name|
17
+ self[:name] = name
18
+ end
15
19
 
16
20
  o.on('-t', '--title TITLE', 'What do you want to register?') do |title|
17
21
  self[:title] = title
@@ -37,9 +41,13 @@ module Timekeeper
37
41
  self[:remove] = id
38
42
  end
39
43
 
40
- o.on('--update ID', 'Remove a record.') do |id|
44
+ o.on('--update ID', 'Update a record.') do |id|
41
45
  self[:update] = id
42
46
  end
47
+
48
+ o.on('--track ID', 'Track a record.') do |id|
49
+ self[:track] = id
50
+ end
43
51
 
44
52
  o.on_tail('-h', '--help', 'Display this help and exit') do
45
53
  puts @opts
@@ -12,9 +12,12 @@ module Timekeeper
12
12
  tk.delete(id)
13
13
  elsif id = options.delete(:update)
14
14
  tk.update(id, options)
15
- else
15
+ elsif id = options.delete(:track)
16
+ tk.track(id, options[:name]) if options[:name]
17
+ else
16
18
  tk.store(options)
17
19
  end
20
+ tk.close
18
21
  else
19
22
  puts options.opts
20
23
  end
@@ -30,6 +33,7 @@ module Timekeeper
30
33
  else
31
34
  puts records
32
35
  end
36
+ tv.close
33
37
  end
34
38
 
35
39
  end
@@ -7,11 +7,18 @@ module Timekeeper
7
7
  end
8
8
 
9
9
  def all
10
- tables.collect{|table| table.query.collect{|attrs| Keep.new(attrs)}}.flatten!
10
+ tables.collect{|table|
11
+ table.query.collect{|attrs|
12
+ keep = Keep.new(attrs)
13
+ keep.tracked = tracked?(keep.name, keep.pk)
14
+ keep
15
+ }
16
+ }.flatten!
11
17
  end
12
18
 
13
19
  def close
14
20
  tables.each {|table| table.close}
21
+ tracking_table.close
15
22
  end
16
23
 
17
24
  def self.export(records, name="timekeeper", type= :csv)
@@ -19,7 +26,7 @@ module Timekeeper
19
26
  case type.to_s
20
27
  when "csv"
21
28
  FasterCSV.open("#{name}.#{type}", "w") do |csv|
22
- csv << records[0].keys
29
+ csv << Keep::FIELDS
23
30
  records.each do |record|
24
31
  csv << record.values
25
32
  end
@@ -34,5 +41,17 @@ module Timekeeper
34
41
  @tables ||= config["team"].collect{|t| Rufus::Tokyo::Table.new(File.join(config["db_path"],"#{t}-time.tct"))}
35
42
  end
36
43
 
44
+ def tracking_table
45
+ @tracking_table ||= Rufus::Tokyo::Table.new(File.join(config["db_path"],"tracking-time.tct"))
46
+ end
47
+
48
+ def tracked?(name, id)
49
+ tracking_table.query{|q|
50
+ q.limit 1
51
+ q.add "name", :equals, name.to_s
52
+ q.add "keep_id", :equals, id.to_s
53
+ }.any?
54
+ end
55
+
37
56
  end
38
57
  end
@@ -17,8 +17,8 @@ module Timekeeper
17
17
  self[:output] = [(file || "timekeeper"), :csv]
18
18
  end
19
19
 
20
- o.on('-n', '--name NAME', 'Query on name') do |title|
21
- self[:title] = title
20
+ o.on('-n', '--name NAME', 'Query on name') do |name|
21
+ self[:name] = name
22
22
  end
23
23
 
24
24
  o.on('-t', '--title TITLE', 'Query on title') do |title|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timekeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - atog