cashflow 0.0.2 → 0.0.5

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: ef9f0c7756918829098a92909f3caa7b6ef8e1f9
4
- data.tar.gz: f3c2bc0c93ff26b93adcd08c06deb509b05d95f6
3
+ metadata.gz: 107cc67b642f951260cc80eac4ee26dc91019d8c
4
+ data.tar.gz: 456365241263c8ef910fe7fe05cea8a7e79bcaf7
5
5
  SHA512:
6
- metadata.gz: 2341886f04cfbc1d896878d4e5c966354afdef260e428e6f6c3ec3065a1cb124bb41d489b83177cc3bfe32b2b901dfd9c11a863f74a8fe7f2683e401f42324ae
7
- data.tar.gz: 510cda8a2669b9e4dcbc68789aba16e5eb5e6c672673543764ba3410d3ea51e9e48a0abf5c7fe76a881470b70a5ca2401956975f6392544eecc8fe6e43fa2683
6
+ metadata.gz: 16c878c53075f8ea22e660b2ac6db3b8069a057d78ff2574d02fa3e24090d256c28afa56440fad16db4c4571a3d59a53800b33b62ec81e2e734669b3a7258aa0
7
+ data.tar.gz: d1921429cf9a762ea6ac6b43442167a0416fd51c8b355ea0362a77a0486a5fdeb43a441354085ce61604b82b60e40936c118bc38714d2c35f03c0d29f46c7df6
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  TODO
19
+ db/cashflow.db
data/README.md CHANGED
@@ -3,7 +3,7 @@ Cashflow
3
3
 
4
4
  **Compare your latest income & expenses to your average.**
5
5
 
6
- Cashflow is a simple command-line application written in Ruby using [Thor](https://github.com/wycats/thor). It's purpose is simple: to analyse your bank transactions (collecting only the _date_ and _amount_) in order to build an average if your income and expenses over the last few months and compare these with the income and expenses for the current month.
6
+ _Cashflow_ is a simple command-line application written in Ruby using [Thor](https://github.com/wycats/thor). It's purpose is simple: to analyse your bank transactions (collecting only the _date_ and _amount_) in order to build an average if your income and expenses over the last few months and compare these with the income and expenses for the current month.
7
7
 
8
8
  Only transactions up to the current day of the month are included, so the app gives you good insight into your financial position at this exact point in the month - extremely useful when you have regular monthly transactions such as rent and salary.
9
9
 
@@ -12,20 +12,22 @@ By default, only transactions from 4 months prior are factored into the calculat
12
12
  Usage
13
13
  -----
14
14
 
15
- Basic useage is simple: you load a set of transactions (in OFX format), then print a report.
15
+ Install via rubygems: `gem install cashflow`. Basic useage is simple. You load a set of transactions (in `ofx` format), then print a report.
16
16
 
17
17
  ![Useage screenshot](https://raw.github.com/6twenty/cashflow/master/screenshot.png)
18
18
 
19
+ Note that _Cashflow_ doesn't care about your net position; it only cares about the comparison to your averages. This means that, as in the example above, even if your net position is negative (ie, you've spent more than you've earned), _Cashflow_ will still report a positive outcome provided you have made an improvement on your average.
20
+
19
21
  Commands
20
22
  --------
21
23
 
22
24
  ```
23
25
  cashflow help # Show this help message
24
- cashflow help [COMMAND] # Describe available commands or one specific command
26
+ cashflow help COMMAND # Describe available commands or one specific command
25
27
  cashflow load PATH # Loads the OFX file at the specified PATH
26
28
  cashflow report # Analyses the stored transactions and prints a comparison report
27
29
  cashflow flush # Flushes the database, removing all stored transactions
28
30
  cashflow version # Prints the current version number
29
31
  ```
30
32
 
31
- **`cashflow report`** takes a single optional parameter. You can specify the date range for the transactions to compare against by passing "-s" or "--span" followed by a number repensenting the number of months to use.
33
+ `cashflow report` takes optional parameters. You can specify the date range for the transactions to compare against by passing `-s` or `--span` followed by a number repensenting the number of months to use. You can also specify the target day of the month to filter transactions against by passing `-d` or `--day` followed by a number representing the desired day of the month.
data/db/.gitkeep ADDED
File without changes
data/lib/cashflow/cli.rb CHANGED
@@ -16,18 +16,29 @@ module Cashflow
16
16
  # Option to factor only up to the day of the month.
17
17
  desc "report", "Analyses the stored transactions and prints a comparison report"
18
18
  option :span, :type => :numeric, :aliases => "-s", :default => 4
19
+ option :day, :type => :numeric, :aliases => "-d"
19
20
  def report
21
+ # Normalize the options.
22
+ months_span = options[:span]
23
+ if options[:day] && options[:day] <= Date.today.day && options[:day] > 0
24
+ day_of_month = options[:day]
25
+ elsif options[:day] && options[:day] <= 0
26
+ day_of_month = 1
27
+ else
28
+ day_of_month = Date.today.day
29
+ end
30
+
20
31
  # Build report.
21
- report = Report.new(options)
22
- report.build_report
32
+ report = Report.new(months_span, day_of_month)
33
+ report.build_report!
23
34
 
24
35
  # Define columns widths.
25
36
  cols = "%-11s %-11s %-11s %-11s\n"
26
37
 
27
38
  # Intro.
28
39
  say("\n")
29
- say("Using transactions up to and including the #{Date.today.day.ordinalize} of the month")
30
- say("Transactions begin #{report.start.strftime('%B')} #{report.start.day.ordinalize}, #{report.start.strftime('%Y')}")
40
+ say("Using transactions up to and including the #{report.end_date.day.ordinalize} of the month")
41
+ say("Transactions begin #{report.start_date.strftime('%B')} #{report.start_date.day.ordinalize}, #{report.start_date.strftime('%Y')}")
31
42
  say("\n")
32
43
 
33
44
  # Table header.
@@ -7,22 +7,34 @@ module Cashflow
7
7
  attr_accessor *TYPES.map { |type| :"#{type}_current_sum" }
8
8
  attr_accessor *TYPES.map { |type| :"#{type}_average" }
9
9
  attr_accessor *TYPES.map { |type| :"#{type}_diff" }
10
- attr_accessor :start
10
+ attr_accessor :start_date, :end_date
11
11
 
12
- def initialize(options)
13
- date = Date.today << options[:span]
14
- @start = Date.new(date.year, date.month, 1)
12
+ def initialize(months_span, day_of_month)
13
+ # Set the initial start date to the first of the month,
14
+ # however many months ago.
15
+ date = Date.today << months_span
16
+ date = Date.new(date.year, date.month, 1)
17
+ # Get the earliest transaction date since the start date (inclusive).
18
+ date = Transaction.all(date).first.date
19
+ # If the earliest transaction took place AFTER the target
20
+ # day of the month, then move to the following month.
21
+ date = date >> 1 if date.day > day_of_month
22
+ # Whatever the final date is, ensure it starts at the beginning of the month.
23
+ @start_date = Date.new(date.year, date.month, 1)
24
+
25
+ # Set the end date.
26
+ @end_date = Date.new(Date.today.year, Date.today.month, day_of_month)
15
27
  end
16
28
 
17
29
  def debits
18
- @debits ||= Transaction.merged(Transaction.debits(start))
30
+ @debits ||= Transaction.merged(Transaction.debits(start_date))
19
31
  end
20
32
 
21
33
  def credits
22
- @credits ||= Transaction.merged(Transaction.credits(start))
34
+ @credits ||= Transaction.merged(Transaction.credits(start_date))
23
35
  end
24
36
 
25
- def build_report
37
+ def build_report!
26
38
  filter_up_to_day_of_the_month!
27
39
  separate_current_month!
28
40
  group_priors_by_month!
@@ -38,7 +50,7 @@ module Cashflow
38
50
  def filter_up_to_day_of_the_month!
39
51
  TYPES.each do |type|
40
52
  filtered = send(type).select do |transaction|
41
- transaction.date.day <= Date.today.day
53
+ transaction.date.day <= end_date.day
42
54
  end
43
55
  send("#{type}=", filtered)
44
56
  end
@@ -95,7 +107,11 @@ module Cashflow
95
107
  # Calculate the average debits & credits based on the prior transactions.
96
108
  def calculate_averages!
97
109
  TYPES.each do |type|
98
- average = send("#{type}_sums").values.inject(0, :+) / send("#{type}_sums").values.length
110
+ begin
111
+ average = send("#{type}_sums").values.inject(0, :+) / send("#{type}_sums").values.length
112
+ rescue
113
+ average = 0
114
+ end
99
115
  send("#{type}_average=", average)
100
116
  end
101
117
  end
@@ -1,3 +1,3 @@
1
1
  module Cashflow
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cashflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Fulcher
@@ -111,7 +111,7 @@ files:
111
111
  - Rakefile
112
112
  - bin/cashflow
113
113
  - cashflow.gemspec
114
- - db/cashflow.db
114
+ - db/.gitkeep
115
115
  - lib/cashflow.rb
116
116
  - lib/cashflow/cli.rb
117
117
  - lib/cashflow/patches.rb
data/db/cashflow.db DELETED
Binary file