watcard 0.0.3 → 0.0.4

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: c946b3c141c0d0328ab669444e0951bc2b00c26c
4
- data.tar.gz: 7b0d61a8e48afdb344daf73878db59536fa525ef
3
+ metadata.gz: db3eab6c54d46f00699e1609a490e8bd91be61c5
4
+ data.tar.gz: dd23c5e11ed1919b58905d2cccb9a9f88f570d6a
5
5
  SHA512:
6
- metadata.gz: c1af6fc7a297b00374378dd5457d4b5fbf6ae651dea5a6b283f0bd97f4cf61ef3dabe3352d295807d6551f0beb2fa4d8693d6bace46b9a8ed6518f271ee5dfab
7
- data.tar.gz: 46072efbe62a64a58802a15fd2c9faecec9f82e7ba561149d44eabcf3afbf5d31e509f630b8f663536903c3d98c0ad6bf96de1a61618d024610c0ea8dcc019be
6
+ metadata.gz: b2f2b029ea8f200283845408e96dd423d32c5c15619ecb3c62f88194be8426853c15e760ca5d3c1dbceb296d3c056dc31303fdf7199a31083b06df09a549b5ed
7
+ data.tar.gz: b4ad1d09d230aa841ba932f7790bb249a5acbce658ba7ff30c2aac995bdfc37c118ab4832505785dfd315e3f2d28a853ac0b35d4322ddcd5b76c420c54bde9dc
@@ -15,15 +15,20 @@ rescue Exception => e
15
15
  end
16
16
 
17
17
  command = ARGV.shift
18
+ days_ago = (ARGV.shift || 0).to_i
19
+ hist = Watcard::History.new(conf)
18
20
  case command
19
21
  when "hist"
20
- hist = Watcard::History.new(conf)
21
- days_ago = (ARGV.shift || 0).to_i
22
22
  hist.output_history(days_ago)
23
23
  when "ledger"
24
- hist = Watcard::History.new(conf)
25
- days_ago = (ARGV.shift || 0).to_i
26
24
  hist.output_ledger(days_ago)
25
+ when "ledgerall"
26
+ hist.output_ledger_all
27
+ when "rawhist"
28
+ hist.output_raw_history(days_ago)
29
+ when "lastadd"
30
+ date = hist.last_ledger_add
31
+ puts "#{(Date.today-date).to_i} days ago on #{date}"
27
32
  else
28
33
  puts "Watcard CLI v#{Watcard::VERSION}"
29
34
  puts "By Tristan Hume"
@@ -3,6 +3,7 @@ require "net/http"
3
3
  require "uri"
4
4
  require "time"
5
5
  require "facets"
6
+ require "yaml"
6
7
 
7
8
  module Watcard
8
9
  class History
@@ -36,6 +37,7 @@ module Watcard
36
37
  return "V1 Cafeteria" if loc =~ /WAT-FS-V1/
37
38
  return "Liquid Assets" if loc =~ /WAT-FS-LA/
38
39
  return "V1 Laundry" if loc =~ /V1 LAUNDRY/
40
+ return "Media.Doc" if loc =~ /MEDIA.DOC/
39
41
  loc
40
42
  end
41
43
 
@@ -51,17 +53,19 @@ module Watcard
51
53
  time: Time.parse(cols[1], date),
52
54
  amount: -(cols[2].strip.to_f)*mult,
53
55
  loc: parse_loc(cols.last),
56
+ raw_loc: cols.last,
54
57
  balance: cols[3].to_i
55
58
  }
56
59
  end.compact.reverse
57
60
  end
58
61
 
59
- def bundle_transactions(hist)
60
- return hist if hist.empty?
62
+ def add_transaction_types(hist)
61
63
  hist.each do |a|
62
64
  h = a[:time].hour
63
65
  type = if a[:loc] =~ /laundry/i
64
66
  "Laundry"
67
+ elsif a[:loc] =~ /media/i
68
+ "Printing"
65
69
  elsif h < 11
66
70
  "Breakfast"
67
71
  elsif h < 17
@@ -71,6 +75,10 @@ module Watcard
71
75
  end
72
76
  a[:meal] = type
73
77
  end
78
+ end
79
+
80
+ def bundle_transactions(hist)
81
+ return hist if hist.empty?
74
82
  meals = [hist.shift]
75
83
  hist.each do |a|
76
84
  # if last meal is same type treat them as one
@@ -96,6 +104,7 @@ module Watcard
96
104
  log "No Transactions"
97
105
  exit
98
106
  end
107
+ add_transaction_types(hist)
99
108
  bundle_transactions(hist)
100
109
  end
101
110
 
@@ -109,11 +118,7 @@ module Watcard
109
118
  END
110
119
  end
111
120
 
112
- def output_ledger(days_ago)
113
- meals = fetch_meals(days_ago)
114
- add_accounts(meals)
115
- log "# Transactions:"
116
- out = meals.map {|m| ledger_transaction(m)}.join('')
121
+ def ledger_append_prompt(out)
117
122
  puts out
118
123
  if STDIN.tty? && @conf['ledger']
119
124
  print "# Add to file [yN]: "
@@ -125,6 +130,29 @@ END
125
130
  end
126
131
  end
127
132
 
133
+ def ledger_transactions(days_ago)
134
+ meals = fetch_meals(days_ago)
135
+ add_accounts(meals)
136
+ meals.map {|m| ledger_transaction(m)}.join('')
137
+ end
138
+
139
+ def output_ledger(days_ago)
140
+ log "# Transactions for #{days_ago} days ago"
141
+ out = ledger_transactions(days_ago)
142
+ ledger_append_prompt(out)
143
+ end
144
+
145
+ def output_ledger_all
146
+ start = (Date.today - last_ledger_add).to_i - 1
147
+ days = []
148
+ start.downto(0).each do |days_ago|
149
+ days << ledger_transactions(days_ago)
150
+ end
151
+ out = days.join('')
152
+ log "# Transactions since #{start} days ago:"
153
+ ledger_append_prompt(out)
154
+ end
155
+
128
156
  def output_history(days_ago)
129
157
  meals = fetch_meals(days_ago)
130
158
  total = 0
@@ -137,5 +165,18 @@ END
137
165
  print " out of $#{budget} surplus: #{sprintf('%.2f',budget-total)}" if budget
138
166
  puts ''
139
167
  end
168
+
169
+ def output_raw_history(days_ago)
170
+ hist = history(Time.now.less(days_ago, :days))
171
+ add_transaction_types(hist)
172
+ puts YAML.dump(hist)
173
+ end
174
+
175
+ def last_ledger_add
176
+ return Date.today unless @conf['ledger']
177
+ file = File.expand_path(@conf['ledger'])
178
+ ledger = IO.read(file)
179
+ Date.parse(ledger.scan(/\d+\/\d+\/\d+/).last)
180
+ end
140
181
  end
141
182
  end
@@ -1,3 +1,3 @@
1
1
  module Watcard
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watcard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Hume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri