tallyit 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/tallyit +17 -8
- data/lib/tallyit/stat_tally.rb +10 -4
- data/lib/tallyit/version.rb +1 -1
- data/tallyit.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38ec3d1e23c22d5fe35efc72c2e5104bf38d08c6
|
4
|
+
data.tar.gz: a6934f2eca2b4f06fce2856521ad919631db2ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7ef6f191e80bdef9c30f4995846c40b97dd262a1ece508638f1558d101ab62b37113cf4aede24a2db281e08b86267f340b6c98f7e71b0daa1a267974c0a9bb8
|
7
|
+
data.tar.gz: 10e40cdb9688d81bc16e50016105abecfcf7ea5b6427d891d96f0a8925c08e4116eb2804523282bf18f8ec798d3fd191c412ac3200f337f3549356450280958f
|
data/exe/tallyit
CHANGED
@@ -4,6 +4,7 @@ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
|
|
4
4
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'tallyit'
|
7
|
+
require 'rainbow'
|
7
8
|
|
8
9
|
options = {
|
9
10
|
:storage_file => File.absolute_path('.tallyit.txt', ENV['HOME']),
|
@@ -14,21 +15,29 @@ options = {
|
|
14
15
|
option_parser = OptionParser.new do |opts|
|
15
16
|
executable_name = File.basename($PROGRAM_NAME)
|
16
17
|
opts.banner = "Usage: #{executable_name} [options] <command>"
|
17
|
-
|
18
|
+
|
19
|
+
opts.separator ""
|
20
|
+
opts.separator "Specific options:"
|
21
|
+
|
22
|
+
opts.on('-i', '--[no-]income', 'Tally type flag, income or expend') do |income|
|
18
23
|
options[:type] = 'income' if income
|
19
24
|
end
|
20
|
-
opts.on('-a AMOUNT', '--amount AMOUNT', Numeric, '
|
25
|
+
opts.on('-a AMOUNT', '--amount AMOUNT', Numeric, 'Require a numeric amount') do |amount|
|
21
26
|
options[:amount] = amount.round(2)
|
22
27
|
end
|
23
|
-
opts.on('-m MSG', '--message MSG', '
|
28
|
+
opts.on('-m MSG', '--message MSG', 'Set message about the tally') do |msg|
|
24
29
|
options[:msg] = msg
|
25
30
|
end
|
26
|
-
opts.on('-l LINE', '--line LINE', Integer, '
|
31
|
+
opts.on('-l LINE', '--line LINE', Integer, 'Choose the lineno to delete') do |line|
|
27
32
|
options[:line] = line
|
28
33
|
end
|
29
|
-
opts.on('
|
34
|
+
opts.on('--format FORMAT', 'Set the output format "table" or "raw", default: "table"') do |format|
|
30
35
|
options[:format] = format
|
31
36
|
end
|
37
|
+
|
38
|
+
opts.separator ""
|
39
|
+
opts.separator "Common options:"
|
40
|
+
|
32
41
|
opts.on_tail('-h', '--help', 'Show help message') do
|
33
42
|
puts opts
|
34
43
|
exit
|
@@ -42,8 +51,8 @@ end
|
|
42
51
|
begin
|
43
52
|
option_parser.parse!
|
44
53
|
if ARGV.empty?
|
45
|
-
puts "
|
46
|
-
puts option_parser
|
54
|
+
STDERR.puts Rainbow("Error: you should supply a command").red.inverse
|
55
|
+
STDERR.puts option_parser
|
47
56
|
exit 1
|
48
57
|
else
|
49
58
|
command = ARGV.shift
|
@@ -51,7 +60,7 @@ begin
|
|
51
60
|
raise OptionParser::InvalidArgument.new("#{command}") unless all_commands.include?(command)
|
52
61
|
end
|
53
62
|
rescue OptionParser::InvalidArgument => ex
|
54
|
-
STDERR.puts ex.message
|
63
|
+
STDERR.puts Rainbow(ex.message).red.inverse
|
55
64
|
STDERR.puts option_parser
|
56
65
|
exit 1
|
57
66
|
end
|
data/lib/tallyit/stat_tally.rb
CHANGED
@@ -12,18 +12,24 @@ module Tallyit
|
|
12
12
|
File.open(file, 'r') do |file|
|
13
13
|
file.each_with_index do |line, index|
|
14
14
|
tmp = line.chomp.split(' | ')
|
15
|
-
tmp[0] == 'income'
|
15
|
+
if tmp[0] == 'income'
|
16
|
+
income_amount << tmp[1].to_f
|
17
|
+
tmp[1] = Rainbow(tmp[1]).green
|
18
|
+
else
|
19
|
+
expend_amount << tmp[1].to_f
|
20
|
+
tmp[1] = Rainbow(tmp[1]).red
|
21
|
+
end
|
16
22
|
t << tmp.unshift(index + 1)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
income_total = income_amount.reduce(0, :+)
|
20
26
|
expend_total = expend_amount.reduce(0, :+)
|
21
27
|
t << :separator
|
22
|
-
t << ['Income total', income_total]
|
28
|
+
t << ['Income total', Rainbow(income_total).green]
|
23
29
|
t << :separator
|
24
|
-
t << ['Expend total', expend_total]
|
30
|
+
t << ['Expend total', Rainbow(expend_total).red]
|
25
31
|
t << :separator
|
26
|
-
t << ['Remaining', income_total - expend_total]
|
32
|
+
t << ['Remaining', Rainbow(income_total - expend_total).blue.inverse]
|
27
33
|
end
|
28
34
|
puts table
|
29
35
|
elsif format == :raw
|
data/lib/tallyit/version.rb
CHANGED
data/tallyit.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
23
|
spec.add_runtime_dependency "terminal-table", "~> 1.5"
|
24
|
+
spec.add_runtime_dependency "rainbow", "~> 2.1"
|
24
25
|
spec.add_development_dependency "bundler", "~> 1.9"
|
25
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallyit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hzlu
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rainbow
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|