timekeeper 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ module Timekeeper
24
24
 
25
25
  def store(attributes)
26
26
  attributes.store(:name, config["name"])
27
- attributes.store(:date, Date.today) unless attributes["date"]
27
+ attributes.store(:date, Date.today) unless (attributes["date"] || attributes[:date])
28
28
  table[table.genuid] = Keep.new(attributes).to_hash
29
29
  end
30
30
 
@@ -26,8 +26,16 @@ module Timekeeper
26
26
  def self.tv(args)
27
27
  options = ViewerOptions.new(args)
28
28
  tv = Viewer.new
29
- tv.config(options.delete(:config)) if options[:config]
30
- records = tv.all
29
+ tv.config(options.delete(:config)) if options[:config]
30
+ records = begin
31
+ if options[:name]
32
+ tv.by_name(options[:name])
33
+ elsif options[:month]
34
+ tv.by_month(options[:month])
35
+ else
36
+ tv.all
37
+ end
38
+ end
31
39
  if output = options.delete(:output)
32
40
  Viewer.export(records, output[0], output[1])
33
41
  else
@@ -5,15 +5,41 @@ module Timekeeper
5
5
  def config(file="timekeeper.yml")
6
6
  @config ||= YAML.load_file(file)
7
7
  end
8
+
9
+ def by_month(m=nil)
10
+ today = Date.today
11
+ y, m = today.year, m || today.month
12
+ select{|q|
13
+ q.add "date", :starts_with, "#{y}-#{sprintf("%02d", m)}"
14
+ }.sort!{|x,y| y.date <=> x.date }
15
+ end
16
+
17
+ def by_name(name)
18
+ select{|q|
19
+ q.add "name", :eq, name
20
+ }.sort!{|x,y| y.date <=> x.date }
21
+ end
22
+
23
+ def select(&block)
24
+ tables.collect{|table|
25
+ table.query{|q|
26
+ yield q
27
+ }.collect{|attrs|
28
+ keep = Keep.new(attrs)
29
+ keep.tracked = tracked?(keep.name, keep.pk)
30
+ keep
31
+ }
32
+ }.flatten
33
+ end
8
34
 
9
35
  def all
10
- tables.collect{|table|
36
+ tables.collect{|table|
11
37
  table.query.collect{|attrs|
12
38
  keep = Keep.new(attrs)
13
39
  keep.tracked = tracked?(keep.name, keep.pk)
14
40
  keep
15
41
  }
16
- }.flatten!
42
+ }.flatten.sort!{|x,y| y.date <=> x.date }
17
43
  end
18
44
 
19
45
  def close
@@ -21,20 +21,20 @@ module Timekeeper
21
21
  self[:name] = name
22
22
  end
23
23
 
24
- o.on('-t', '--title TITLE', 'Query on title') do |title|
25
- self[:title] = title
26
- end
24
+ # o.on('-t', '--title TITLE', 'Query on title') do |title|
25
+ # self[:title] = title
26
+ # end
27
27
 
28
- o.on('-c', '--target TARGET', 'Query on target') do |target|
29
- self[:target] = target
30
- end
28
+ # o.on('-c', '--target TARGET', 'Query on target') do |target|
29
+ # self[:target] = target
30
+ # end
31
31
 
32
- o.on('-m', '--description DESCRIPTION', 'Query on description') do |description|
33
- self[:description] = description
34
- end
32
+ # o.on('-m', '--description DESCRIPTION', 'Query on description') do |description|
33
+ # self[:description] = description
34
+ # end
35
35
 
36
- o.on('-d', '--date DATE', 'Query on date') do |date|
37
- self[:date] = date
36
+ o.on('--month [month]', 'Query on month') do |month|
37
+ self[:month] = month || Date.today.month
38
38
  end
39
39
 
40
40
  o.on_tail('-h', '--help', 'Display this help and exit') do
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - atog
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-01 00:00:00 +02:00
12
+ date: 2009-10-05 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency