Class: Timekeeper::Viewer

Inherits:
Object
  • Object
show all
Defined in:
lib/timekeeper/viewer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.export(records, name = "timekeeper", type = :csv) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/timekeeper/viewer.rb', line 50

def self.export(records, name="timekeeper", type= :csv)
  if records.any?
    case type.to_s
    when "csv"
      FasterCSV.open("#{name}.#{type}", "w") do |csv|    
        csv << Keep::FIELDS
        records.each do |record|
          csv << record.values
        end
      end
    end
  end
end

Instance Method Details

#allObject



35
36
37
38
39
40
41
42
43
# File 'lib/timekeeper/viewer.rb', line 35

def all
  tables.collect{|table|
    table.query.collect{|attrs|
      keep = Keep.new(attrs)
      keep.tracked = tracked?(keep.name, keep.pk)
      keep
    }
  }.flatten.sort!{|x,y| y.date <=> x.date }
end

#by_month(m = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/timekeeper/viewer.rb', line 9

def by_month(m=nil)
  today = Date.today
  y, m = today.year, m || today.month
  select{|q|
    q.add "date", :starts_with, "#{y}-#{sprintf("%02d", m)}"
  }.sort!{|x,y| y.date <=> x.date }
end

#by_name(name) ⇒ Object



17
18
19
20
21
# File 'lib/timekeeper/viewer.rb', line 17

def by_name(name)
  select{|q|
    q.add "name", :eq, name
  }.sort!{|x,y| y.date <=> x.date }
end

#closeObject



45
46
47
48
# File 'lib/timekeeper/viewer.rb', line 45

def close
  tables.each {|table| table.close}
  tracking_table.close
end

#config(file = "timekeeper.yml") ⇒ Object



5
6
7
# File 'lib/timekeeper/viewer.rb', line 5

def config(file="timekeeper.yml")
  @config ||= YAML.load_file(file)
end

#select(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/timekeeper/viewer.rb', line 23

def select(&block)
  tables.collect{|table|
    table.query{|q|
      yield q     
    }.collect{|attrs|
      keep = Keep.new(attrs)
      keep.tracked = tracked?(keep.name, keep.pk)
      keep
    }
  }.flatten
end