tallyit 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 967c596e1ae14bbc98ee761b71e1db4ff467f51a
4
+ data.tar.gz: e831065aa07d94f125e1a26efde34ec6a74d2667
5
+ SHA512:
6
+ metadata.gz: 587125b2befbf3a737ac2b651a156130700245843e39a29fb61f89838e72e7b9f1b107fc19b9797251781134573ad796f9c2229f83ab9f02c05d614c5f99911b
7
+ data.tar.gz: 8d8dfd0386079dcec34904996d4f4e464869b6739d258f28a9cd5d15643661021d692a5f644f374db293cb916750fe12f75d4878bde059a7f11b20cf32b0c19d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tallyit.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Tallyit
2
+
3
+ It is a command line tool for taking notes about your financial balance.
4
+
5
+ ## Installation
6
+
7
+ $ gem install tallyit
8
+
9
+ ## Usage
10
+
11
+ #### add a income tally
12
+
13
+ $ tallyit --income -a 10000 -m "your msg about this tally" add
14
+
15
+ #### add a expend tally
16
+
17
+ $ tallyit -a 10000 -m "buy something" add
18
+
19
+ #### show all records
20
+
21
+ $ tallyit show
22
+
23
+ #### more info
24
+
25
+ $ tallyit --help
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/hzlu/tallyit/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tallyit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/tallyit ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
4
+
5
+ require 'optparse'
6
+ require 'tallyit'
7
+
8
+ options = {
9
+ :storage_file => File.absolute_path('.tallyit.txt', ENV['HOME']),
10
+ :type => 'expend',
11
+ :format => 'table'
12
+ }
13
+
14
+ option_parser = OptionParser.new do |opts|
15
+ executable_name = File.basename($PROGRAM_NAME)
16
+ opts.banner = "Usage: #{executable_name} [options] <command>"
17
+ opts.on('-i', '--[no-]income', 'it is a income tally') do |income|
18
+ options[:type] = 'income' if income
19
+ end
20
+ opts.on('-a AMOUNT', '--amount AMOUNT', Numeric, 'tally amount') do |amount|
21
+ options[:amount] = amount.round(2)
22
+ end
23
+ opts.on('-m MSG', '--message MSG', 'tally message') do |msg|
24
+ options[:msg] = msg
25
+ end
26
+ opts.on('-l LINE', '--line LINE', Integer, 'choose tally line to delete') do |line|
27
+ options[:line] = line
28
+ end
29
+ opts.on('-f FORMAT', '--format FORMAT', 'output format') do |format|
30
+ options[:format] = format
31
+ end
32
+ opts.on_tail('-h', '--help', 'Show help message') do
33
+ puts opts
34
+ exit
35
+ end
36
+ opts.on_tail('-v', '--version', 'Show version') do
37
+ puts Tallyit::VERSION
38
+ exit
39
+ end
40
+ end
41
+
42
+ begin
43
+ option_parser.parse!
44
+ if ARGV.empty?
45
+ puts "error: you should supply a command"
46
+ puts option_parser.help
47
+ exit 1
48
+ else
49
+ command = ARGV.shift
50
+ all_commands = %w(add delete stat)
51
+ raise OptionParser::InvalidArgument.new("#{command}") unless all_commands.include?(command)
52
+ end
53
+ rescue OptionParser::InvalidArgument => ex
54
+ STDERR.puts ex.message
55
+ STDERR.puts option_parser
56
+ exit 1
57
+ end
58
+
59
+ Tally = Struct.new(:type, :amount, :msg)
60
+ tally = Tally.new(options[:type], options[:amount], options[:msg])
61
+ case command
62
+ when 'add'
63
+ Tallyit.add(tally, options[:storage_file])
64
+ when 'delete'
65
+ Tallyit.delete(options[:storage_file], options[:line])
66
+ when 'stat'
67
+ Tallyit.stat(options[:storage_file], options[:format])
68
+ end
69
+
data/lib/tallyit.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "tallyit/add_tally"
2
+ require "tallyit/delete_tally"
3
+ require "tallyit/stat_tally"
4
+ require "tallyit/version"
5
+
6
+ module Tallyit
7
+ def self.add(tally, file)
8
+ Tallyit::AddTally.do(tally, file)
9
+ end
10
+
11
+ def self.delete(file, lineno)
12
+ Tallyit::DeleteTally.do(file, lineno.to_i)
13
+ end
14
+
15
+ def self.stat(file, format)
16
+ Tallyit::StatTally.do(file, format.to_sym)
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Tallyit
2
+ module AddTally
3
+ def self.do(tally, file)
4
+ File.open(file, 'a') do |file|
5
+ file.puts "#{tally.type} | #{tally.amount} | #{tally.msg} | #{Time.now}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Tallyit
2
+ module DeleteTally
3
+ def self.do(file, lineno)
4
+ File.open(file + '.tmp', 'w') do |tmp_file|
5
+ File.open(file, 'r') do |file|
6
+ file.each_with_index do |line, index|
7
+ next if index + 1 == lineno
8
+ tmp_file.puts line
9
+ end
10
+ end
11
+ end
12
+ `mv #{file + '.tmp'} #{file}`
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,38 @@
1
+ require 'terminal-table'
2
+
3
+ module Tallyit
4
+ module StatTally
5
+ def self.do(file, format = :table)
6
+ if format == :table
7
+ income_amount = []
8
+ expend_amount = []
9
+ table = Terminal::Table.new do |t|
10
+ t.title = "Balance Table"
11
+ t.headings = ['ID', 'Type', 'Amount', 'Msg', 'Time']
12
+ File.open(file, 'r') do |file|
13
+ file.each_with_index do |line, index|
14
+ tmp = line.chomp.split(' | ')
15
+ tmp[0] == 'income' ? income_amount << tmp[1].to_f : expend_amount << tmp[1].to_f
16
+ t << tmp.unshift(index + 1)
17
+ end
18
+ end
19
+ income_total = income_amount.reduce(0, :+)
20
+ expend_total = expend_amount.reduce(0, :+)
21
+ t << :separator
22
+ t << ['Income total', income_total]
23
+ t << :separator
24
+ t << ['Expend total', expend_total]
25
+ t << :separator
26
+ t << ['Remaining', income_total - expend_total]
27
+ end
28
+ puts table
29
+ elsif format == :raw
30
+ File.open(file, 'r') do |file|
31
+ file.each_line do |line|
32
+ puts line
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Tallyit
2
+ VERSION = "0.1.0"
3
+ end
data/tallyit.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tallyit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tallyit"
8
+ spec.version = Tallyit::VERSION
9
+ spec.authors = ["hzlu"]
10
+ spec.email = ["hzlu2010@gmail.com"]
11
+
12
+ spec.summary = %q{take notes about your balance}
13
+ spec.description = %q{take a daily tally use command line}
14
+ spec.homepage = "https://github.com/hzlu/tallyit"
15
+
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "terminal-table", "~> 1.5"
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tallyit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hzlu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terminal-table
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: take a daily tally use command line
56
+ email:
57
+ - hzlu2010@gmail.com
58
+ executables:
59
+ - tallyit
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/tallyit
72
+ - lib/tallyit.rb
73
+ - lib/tallyit/add_tally.rb
74
+ - lib/tallyit/delete_tally.rb
75
+ - lib/tallyit/stat_tally.rb
76
+ - lib/tallyit/version.rb
77
+ - tallyit.gemspec
78
+ homepage: https://github.com/hzlu/tallyit
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: take notes about your balance
102
+ test_files: []