reckon 0.6.0 → 0.6.1
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 +4 -4
- data/.github/workflows/ruby.yml +50 -0
- data/.gitignore +2 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +23 -3
- data/Gemfile.lock +1 -1
- data/README.md +72 -16
- data/Rakefile +17 -1
- data/lib/reckon/app.rb +10 -5
- data/lib/reckon/csv_parser.rb +2 -7
- data/lib/reckon/date_column.rb +10 -0
- data/lib/reckon/money.rb +48 -48
- data/lib/reckon/version.rb +1 -1
- data/spec/integration/another_bank_example/input.csv +9 -0
- data/spec/integration/another_bank_example/output.ledger +36 -0
- data/spec/integration/another_bank_example/test_args +1 -0
- data/spec/integration/austrian_example/input.csv +13 -0
- data/spec/integration/austrian_example/output.ledger +52 -0
- data/spec/integration/austrian_example/test_args +2 -0
- data/spec/integration/bom_utf8_file/input.csv +3 -0
- data/spec/integration/bom_utf8_file/output.ledger +4 -0
- data/spec/integration/bom_utf8_file/test_args +3 -0
- data/spec/integration/broker_canada_example/input.csv +12 -0
- data/spec/integration/broker_canada_example/output.ledger +48 -0
- data/spec/integration/broker_canada_example/test_args +1 -0
- data/spec/integration/chase/account_tokens_and_regex/output.ledger +36 -0
- data/spec/integration/chase/account_tokens_and_regex/test_args +2 -0
- data/spec/integration/chase/account_tokens_and_regex/tokens.yml +16 -0
- data/spec/integration/chase/default_account_names/output.ledger +36 -0
- data/spec/integration/chase/default_account_names/test_args +3 -0
- data/spec/integration/chase/input.csv +9 -0
- data/spec/integration/chase/learn_from_existing/learn.ledger +7 -0
- data/spec/integration/chase/learn_from_existing/output.ledger +36 -0
- data/spec/integration/chase/learn_from_existing/test_args +1 -0
- data/spec/integration/chase/simple/output.ledger +36 -0
- data/spec/integration/chase/simple/test_args +1 -0
- data/spec/integration/danish_kroner_nordea_example/input.csv +6 -0
- data/spec/integration/danish_kroner_nordea_example/output.ledger +24 -0
- data/spec/integration/danish_kroner_nordea_example/test_args +1 -0
- data/spec/integration/english_date_example/input.csv +3 -0
- data/spec/integration/english_date_example/output.ledger +12 -0
- data/spec/integration/english_date_example/test_args +1 -0
- data/spec/integration/extratofake/input.csv +24 -0
- data/spec/integration/extratofake/output.ledger +92 -0
- data/spec/integration/extratofake/test_args +1 -0
- data/spec/integration/french_example/input.csv +9 -0
- data/spec/integration/french_example/output.ledger +36 -0
- data/spec/integration/french_example/test_args +2 -0
- data/spec/integration/german_date_example/input.csv +3 -0
- data/spec/integration/german_date_example/output.ledger +12 -0
- data/spec/integration/german_date_example/test_args +1 -0
- data/spec/integration/harder_date_example/input.csv +5 -0
- data/spec/integration/harder_date_example/output.ledger +20 -0
- data/spec/integration/harder_date_example/test_args +1 -0
- data/spec/integration/ing/input.csv +3 -0
- data/spec/integration/ing/output.ledger +12 -0
- data/spec/integration/ing/test_args +1 -0
- data/spec/integration/intuit_mint_example/input.csv +7 -0
- data/spec/integration/intuit_mint_example/output.ledger +28 -0
- data/spec/integration/intuit_mint_example/test_args +1 -0
- data/spec/integration/invalid_header_example/input.csv +6 -0
- data/spec/integration/invalid_header_example/output.ledger +8 -0
- data/spec/integration/invalid_header_example/test_args +1 -0
- data/spec/integration/inversed_credit_card/input.csv +16 -0
- data/spec/integration/inversed_credit_card/output.ledger +64 -0
- data/spec/integration/inversed_credit_card/test_args +1 -0
- data/spec/integration/nationwide/input.csv +4 -0
- data/spec/integration/nationwide/output.ledger +16 -0
- data/spec/integration/nationwide/test_args +1 -0
- data/spec/integration/regression/issue_51_account_tokens/input.csv +8 -0
- data/spec/integration/regression/issue_51_account_tokens/output.ledger +32 -0
- data/spec/integration/regression/issue_51_account_tokens/test_args +4 -0
- data/spec/integration/regression/issue_51_account_tokens/tokens.yml +9 -0
- data/spec/integration/regression/issue_64_date_column/input.csv +3 -0
- data/spec/integration/regression/issue_64_date_column/output.ledger +8 -0
- data/spec/integration/regression/issue_64_date_column/test_args +1 -0
- data/spec/integration/regression/issue_73_account_token_matching/input.csv +2 -0
- data/spec/integration/regression/issue_73_account_token_matching/output.ledger +4 -0
- data/spec/integration/regression/issue_73_account_token_matching/test_args +6 -0
- data/spec/integration/regression/issue_73_account_token_matching/tokens.yml +8 -0
- data/spec/integration/regression/issue_85_date_example/input.csv +2 -0
- data/spec/integration/regression/issue_85_date_example/output.ledger +8 -0
- data/spec/integration/regression/issue_85_date_example/test_args +1 -0
- data/spec/integration/spanish_date_example/input.csv +3 -0
- data/spec/integration/spanish_date_example/output.ledger +12 -0
- data/spec/integration/spanish_date_example/test_args +1 -0
- data/spec/integration/suntrust/input.csv +7 -0
- data/spec/integration/suntrust/output.ledger +28 -0
- data/spec/integration/suntrust/test_args +1 -0
- data/spec/integration/test.sh +82 -0
- data/spec/integration/test_money_column/input.csv +3 -0
- data/spec/integration/test_money_column/output.ledger +8 -0
- data/spec/integration/test_money_column/test_args +1 -0
- data/spec/integration/two_money_columns/input.csv +5 -0
- data/spec/integration/two_money_columns/output.ledger +20 -0
- data/spec/integration/two_money_columns/test_args +1 -0
- data/spec/integration/yyyymmdd_date_example/input.csv +1 -0
- data/spec/integration/yyyymmdd_date_example/output.ledger +4 -0
- data/spec/integration/yyyymmdd_date_example/test_args +1 -0
- data/spec/reckon/money_column_spec.rb +24 -24
- data/spec/reckon/money_spec.rb +13 -32
- metadata +93 -7
- data/.travis.yml +0 -13
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
01/09/2015,05354 SUBWAY,8.19,,1000.00
|
|
2
|
+
02/18/2015,WENDY'S #6338,8.55,,1000.00
|
|
3
|
+
02/25/2015,WENDY'S #6338,8.55,,1000.00
|
|
4
|
+
02/25/2015,WENDY'S #6338,9.14,,1000.00
|
|
5
|
+
02/27/2015,WENDY'S #6338,5.85,,1000.00
|
|
6
|
+
03/09/2015,WENDY'S #6338,17.70,,1000.00
|
|
7
|
+
03/16/2015,WENDY'S #6338,11.15,,1000.00
|
|
8
|
+
03/23/2015,WENDY'S,10.12,,1000.00
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
2015-01-09 05354 SUBWAY
|
|
2
|
+
Assets:Chequing $8.19
|
|
3
|
+
Expenses:Dining:Resturant
|
|
4
|
+
|
|
5
|
+
2015-02-18 WENDY'S #6338
|
|
6
|
+
Assets:Chequing $8.55
|
|
7
|
+
Expenses:Dining:Resturant
|
|
8
|
+
|
|
9
|
+
2015-02-25 WENDY'S #6338
|
|
10
|
+
Assets:Chequing $9.14
|
|
11
|
+
Expenses:Dining:Resturant
|
|
12
|
+
|
|
13
|
+
2015-02-25 WENDY'S #6338
|
|
14
|
+
Assets:Chequing $8.55
|
|
15
|
+
Expenses:Dining:Resturant
|
|
16
|
+
|
|
17
|
+
2015-02-27 WENDY'S #6338
|
|
18
|
+
Assets:Chequing $5.85
|
|
19
|
+
Expenses:Dining:Resturant
|
|
20
|
+
|
|
21
|
+
2015-03-09 WENDY'S #6338
|
|
22
|
+
Assets:Chequing $17.70
|
|
23
|
+
Expenses:Dining:Resturant
|
|
24
|
+
|
|
25
|
+
2015-03-16 WENDY'S #6338
|
|
26
|
+
Assets:Chequing $11.15
|
|
27
|
+
Expenses:Dining:Resturant
|
|
28
|
+
|
|
29
|
+
2015-03-23 WENDY'S
|
|
30
|
+
Assets:Chequing $10.12
|
|
31
|
+
Expenses:Dining:Resturant
|
|
32
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
2009-12-02 BLARG R SH 456930; $1,826.06
|
|
2
|
+
Assets:Bank:Checking $327.49
|
|
3
|
+
Income:Unknown
|
|
4
|
+
|
|
5
|
+
2009-12-02 Check - 0000000122; 122; $1,750.06
|
|
6
|
+
Income:Unknown
|
|
7
|
+
Assets:Bank:Checking -$76.00
|
|
8
|
+
|
|
9
|
+
2009-12-02 Check - 0000000112; 112; $1,498.57
|
|
10
|
+
Income:Unknown
|
|
11
|
+
Assets:Bank:Checking -$800.00
|
|
12
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking --date-format '%d/%m/%Y'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
11/01/2014,0, Deposit,0,500.00,500.00
|
|
2
|
+
11/02/2014,101,Check,100.00,0,400.00
|
|
3
|
+
11/03/2014,102,Check,100.00,0,300.00
|
|
4
|
+
11/04/2014,103,Check,100.00,0,200.00
|
|
5
|
+
11/05/2014,104,Check,100.00,0,100.00
|
|
6
|
+
11/06/2014,105,Check,100.00,0,0.00
|
|
7
|
+
11/17/2014,0, Deposit,0,700.00,700.00
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
2014-11-01 0; Deposit; 500.00
|
|
2
|
+
Assets:Bank:Checking $500.00
|
|
3
|
+
Income:Unknown
|
|
4
|
+
|
|
5
|
+
2014-11-02 101; Check; 400.00
|
|
6
|
+
Expenses:Unknown
|
|
7
|
+
Assets:Bank:Checking -$100.00
|
|
8
|
+
|
|
9
|
+
2014-11-03 102; Check; 300.00
|
|
10
|
+
Expenses:Unknown
|
|
11
|
+
Assets:Bank:Checking -$100.00
|
|
12
|
+
|
|
13
|
+
2014-11-04 103; Check; 200.00
|
|
14
|
+
Expenses:Unknown
|
|
15
|
+
Assets:Bank:Checking -$100.00
|
|
16
|
+
|
|
17
|
+
2014-11-05 104; Check; 100.00
|
|
18
|
+
Expenses:Unknown
|
|
19
|
+
Assets:Bank:Checking -$100.00
|
|
20
|
+
|
|
21
|
+
2014-11-06 105; Check; 0.00
|
|
22
|
+
Expenses:Unknown
|
|
23
|
+
Assets:Bank:Checking -$100.00
|
|
24
|
+
|
|
25
|
+
2014-11-17 0; Deposit; 700.00
|
|
26
|
+
Assets:Bank:Checking $700.00
|
|
27
|
+
Income:Unknown
|
|
28
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# set -x
|
|
4
|
+
|
|
5
|
+
set -Euo pipefail
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
8
|
+
TEST_DIFF=""
|
|
9
|
+
OUTPUT=""
|
|
10
|
+
RECKON_CMD="env RUBYLIB=$SCRIPT_DIR/../../lib:$RUBYLIB reckon -v"
|
|
11
|
+
|
|
12
|
+
main () {
|
|
13
|
+
trap test_fail EXIT
|
|
14
|
+
|
|
15
|
+
if [[ $# -eq 1 ]]; then
|
|
16
|
+
TESTS=$1/test_args
|
|
17
|
+
else
|
|
18
|
+
TESTS=$(find "$SCRIPT_DIR" -name 'test_args')
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
echo > test.log
|
|
22
|
+
|
|
23
|
+
for t in $TESTS; do
|
|
24
|
+
OUTPUT_FILE=$(mktemp)
|
|
25
|
+
TEST_DIR=$(dirname "$t")
|
|
26
|
+
pushd "$TEST_DIR" >/dev/null || exit 1
|
|
27
|
+
echo "$TEST_DIR Running..."
|
|
28
|
+
TEST_CMD="$RECKON_CMD -o $OUTPUT_FILE $(cat test_args)"
|
|
29
|
+
TEST_LOG=$(eval "$TEST_CMD" 2>&1)
|
|
30
|
+
ERROR=0
|
|
31
|
+
|
|
32
|
+
compare_output "$OUTPUT_FILE"
|
|
33
|
+
|
|
34
|
+
popd >/dev/null || exit 1
|
|
35
|
+
# have to save output after popd
|
|
36
|
+
echo -e "\n\n======>$TEST_DIR" >> test.log
|
|
37
|
+
echo -e "TEST_CMD\n$TEST_LOG" >> test.log
|
|
38
|
+
|
|
39
|
+
if [[ $ERROR -ne 0 ]]; then
|
|
40
|
+
exit 1
|
|
41
|
+
fi
|
|
42
|
+
done
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test_fail () {
|
|
46
|
+
STATUS=$?
|
|
47
|
+
if [[ $STATUS -ne 0 ]]; then
|
|
48
|
+
echo -e "FAILED!!!\n$TEST_DIFF\nTest output saved to $OUTPUT_FILE\n"
|
|
49
|
+
exit $STATUS
|
|
50
|
+
fi
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
compare_output_for () {
|
|
54
|
+
OUTPUT_FILE=$1
|
|
55
|
+
LEDGER=$2
|
|
56
|
+
|
|
57
|
+
TEST_DIFF=$(diff -u <($LEDGER -f output.ledger r --date-format %F 2>&1) <($LEDGER -f "$OUTPUT_FILE" r --date-format %F 2>&1) )
|
|
58
|
+
|
|
59
|
+
# ${#} is character length, test that there was no output from diff
|
|
60
|
+
if [ ${#TEST_DIFF} -eq 0 ]; then
|
|
61
|
+
return 0
|
|
62
|
+
else
|
|
63
|
+
return 1
|
|
64
|
+
fi
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
compare_output () {
|
|
68
|
+
OUTPUT_FILE=$1
|
|
69
|
+
|
|
70
|
+
for n in {ledger,hledger}; do
|
|
71
|
+
echo -n " - $n..."
|
|
72
|
+
if compare_output_for "$OUTPUT_FILE" "$n"; then
|
|
73
|
+
echo "SUCCESS!"
|
|
74
|
+
else
|
|
75
|
+
echo "FAILED!"
|
|
76
|
+
ERROR=1
|
|
77
|
+
return 0
|
|
78
|
+
fi
|
|
79
|
+
done
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main "$@"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
4/1/2008,Check - 0000000122,122,-$76.00,"","$1,750.06"
|
|
2
|
+
3/28/2008,BLARG R SH 456930,"","",+$327.49,"$1,826.06"
|
|
3
|
+
3/27/2008,Check - 0000000112,112,-$800.00,"","$1,498.57"
|
|
4
|
+
3/26/2008,Check - 0000000251,251,-$88.55,"","$1,298.57"
|
|
5
|
+
3/26/2008,Check - 0000000251,251,"","+$88.55","$1,298.57"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
2008-03-26 Check - 0000000251; 251; $1,298.57
|
|
2
|
+
Assets:Bank:Checking $88.55
|
|
3
|
+
Income:Unknown
|
|
4
|
+
|
|
5
|
+
2008-03-26 Check - 0000000251; 251; $1,298.57
|
|
6
|
+
Income:Unknown
|
|
7
|
+
Assets:Bank:Checking -$88.55
|
|
8
|
+
|
|
9
|
+
2008-03-27 Check - 0000000112; 112; $1,498.57
|
|
10
|
+
Income:Unknown
|
|
11
|
+
Assets:Bank:Checking -$800.00
|
|
12
|
+
|
|
13
|
+
2008-03-28 BLARG R SH 456930; $1,826.06
|
|
14
|
+
Assets:Bank:Checking $327.49
|
|
15
|
+
Income:Unknown
|
|
16
|
+
|
|
17
|
+
2008-04-01 Check - 0000000122; 122; $1,750.06
|
|
18
|
+
Income:Unknown
|
|
19
|
+
Assets:Bank:Checking -$76.00
|
|
20
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DEBIT,20121231,"ODESK***BAL-27DEC12 650-12345 CA 12/28",-123.45
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f input.csv --unattended --account Assets:Bank:Checking
|
|
@@ -8,13 +8,13 @@ require 'reckon'
|
|
|
8
8
|
describe Reckon::MoneyColumn do
|
|
9
9
|
describe "initialize" do
|
|
10
10
|
it "should convert strings into Money" do
|
|
11
|
-
Reckon::MoneyColumn.new( ["1.00", "-2.00"] ).should == [
|
|
11
|
+
Reckon::MoneyColumn.new( ["1.00", "-2.00"] ).should == [
|
|
12
12
|
Reckon::Money.new( 1.00 ), Reckon::Money.new( -2.00 ) ]
|
|
13
13
|
end
|
|
14
14
|
it "should convert empty string into nil" do
|
|
15
|
-
Reckon::MoneyColumn.new( ["1.00", ""] ).should == [
|
|
15
|
+
Reckon::MoneyColumn.new( ["1.00", ""] ).should == [
|
|
16
16
|
Reckon::Money.new( 1.00 ), nil ]
|
|
17
|
-
Reckon::MoneyColumn.new( ["", "-2.00"] ).should == [
|
|
17
|
+
Reckon::MoneyColumn.new( ["", "-2.00"] ).should == [
|
|
18
18
|
nil, Reckon::Money.new( -2.00 ) ]
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -32,33 +32,33 @@ describe Reckon::MoneyColumn do
|
|
|
32
32
|
|
|
33
33
|
describe "merge" do
|
|
34
34
|
it "should merge two columns" do
|
|
35
|
-
Reckon::MoneyColumn.new(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Reckon::MoneyColumn.new(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
35
|
+
m1 = Reckon::MoneyColumn.new(["1.00", ""])
|
|
36
|
+
m2 = Reckon::MoneyColumn.new(["", "-2.00"])
|
|
37
|
+
expect(m1.merge!(m2)).to(
|
|
38
|
+
eq([Reckon::Money.new(1.00), Reckon::Money.new(-2.00)])
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
m1 = Reckon::MoneyColumn.new(["1.00", "0"])
|
|
42
|
+
m2 = Reckon::MoneyColumn.new(["0", "-2.00"])
|
|
43
|
+
expect(m1.merge!(m2)).to(
|
|
44
|
+
eq([Reckon::Money.new(1.00), Reckon::Money.new(-2.00)])
|
|
45
|
+
)
|
|
46
|
+
end
|
|
48
47
|
|
|
49
48
|
it "should return nil if columns cannot be merged" do
|
|
50
|
-
Reckon::MoneyColumn.new(
|
|
51
|
-
|
|
49
|
+
m1 = Reckon::MoneyColumn.new(["1.00", ""])
|
|
50
|
+
m2 = Reckon::MoneyColumn.new(["1.00", "-2.00"])
|
|
51
|
+
expect(m1.merge!(m2)).to eq([Reckon::Money.new(0), Reckon::Money.new(-2)])
|
|
52
52
|
|
|
53
|
-
Reckon::MoneyColumn.new(
|
|
54
|
-
|
|
53
|
+
m1 = Reckon::MoneyColumn.new(["From1", "Names"])
|
|
54
|
+
m2 = Reckon::MoneyColumn.new(["Acc", "NL28 INGB 1200 3244 16,21817"])
|
|
55
|
+
expect(m1.merge!(m2)).to eq([Reckon::Money.new(-1), Reckon::Money.new("NL28 INGB 1200 3244 16,21817")])
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
it "should invert first column if both positive" do
|
|
58
|
-
|
|
59
|
-
Reckon::MoneyColumn.new( ["", "2.00"]
|
|
60
|
-
|
|
59
|
+
expect(
|
|
60
|
+
Reckon::MoneyColumn.new(["1.00", ""]).merge!(Reckon::MoneyColumn.new( ["", "2.00"]))
|
|
61
|
+
).to eq([Reckon::Money.new(-1.00), Reckon::Money.new(2.00)])
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
|
-
|
data/spec/reckon/money_spec.rb
CHANGED
|
@@ -6,45 +6,26 @@ require 'rubygems'
|
|
|
6
6
|
require 'reckon'
|
|
7
7
|
|
|
8
8
|
describe Reckon::Money do
|
|
9
|
-
describe "
|
|
9
|
+
describe "parse" do
|
|
10
10
|
it "should handle currency indicators" do
|
|
11
|
-
expect(Reckon::Money
|
|
12
|
-
expect(Reckon::Money
|
|
13
|
-
expect(Reckon::Money
|
|
11
|
+
expect(Reckon::Money.new( "$2.00" )).to eq(2.00)
|
|
12
|
+
expect(Reckon::Money.new("-$1025.67")).to eq(-1025.67)
|
|
13
|
+
expect(Reckon::Money.new("$-1025.67")).to eq(-1025.67)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "should handle the comma_separates_cents option correctly" do
|
|
17
|
-
expect(Reckon::Money
|
|
18
|
-
expect(Reckon::Money
|
|
19
|
-
expect(Reckon::Money
|
|
17
|
+
expect(Reckon::Money.new("$2,00", comma_separates_cents: true)).to eq(2.00)
|
|
18
|
+
expect(Reckon::Money.new("-$1025,67", comma_separates_cents: true)).to eq(-1025.67)
|
|
19
|
+
expect(Reckon::Money.new("$-1025,67", comma_separates_cents: true)).to eq(-1025.67)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should return 0 for an empty string" do
|
|
23
|
-
expect(Reckon::Money
|
|
23
|
+
expect(Reckon::Money.new("")).to eq(0)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "should handle 1000 indicators correctly" do
|
|
27
|
-
expect(Reckon::Money
|
|
28
|
-
expect(Reckon::Money
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should keep numbers together" do
|
|
32
|
-
expect(Reckon::Money::from_s("1A1")).to eq(1)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should prefer numbers with precision of two" do
|
|
36
|
-
expect(Reckon::Money::from_s("1A2.00")).to eq(2)
|
|
37
|
-
expect(Reckon::Money::from_s("2.00A1")).to eq(2)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "should handle arbitrary prefixes and postfixes" do
|
|
41
|
-
expect(Reckon::Money::from_s("AB1.00C")).to eq(1)
|
|
42
|
-
expect(Reckon::Money::from_s("AB0C")).to eq(0)
|
|
43
|
-
expect(Reckon::Money::from_s("AB-2.00C")).to eq(-2)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should return nil if no numbers are found" do
|
|
47
|
-
expect(Reckon::Money::from_s("BAC")).to be_nil()
|
|
27
|
+
expect(Reckon::Money.new("$2.000,00", comma_separates_cents: true)).to eq(2000.00)
|
|
28
|
+
expect(Reckon::Money.new("-$1,025.67")).to eq(-1025.67)
|
|
48
29
|
end
|
|
49
30
|
end
|
|
50
31
|
|
|
@@ -60,14 +41,14 @@ describe Reckon::Money do
|
|
|
60
41
|
end
|
|
61
42
|
|
|
62
43
|
it "work with suffixed currencies such as SEK" do
|
|
63
|
-
expect(Reckon::Money.new(
|
|
64
|
-
expect(Reckon::Money.new(
|
|
44
|
+
expect(Reckon::Money.new(-20.00, currency: "SEK", suffixed: true).pretty).to eq("-20.00 SEK")
|
|
45
|
+
expect(Reckon::Money.new(1558.52, currency: "SEK", suffixed: true).pretty).to eq(" 1558.52 SEK")
|
|
65
46
|
end
|
|
66
47
|
end
|
|
67
48
|
|
|
68
49
|
describe "likelihood" do
|
|
69
50
|
it "should return the likelihood that a string represents money" do
|
|
70
|
-
expect(Reckon::Money::likelihood(
|
|
51
|
+
expect(Reckon::Money::likelihood("$20.00")).to eq(65)
|
|
71
52
|
end
|
|
72
53
|
|
|
73
54
|
it "should return neutral for empty string" do
|