formatted-money 0.0.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.
- data/LICENSE +7 -0
- data/README.md +34 -0
- data/Rakefile +32 -0
- data/doc/FormattedMoney.html +1144 -0
- data/doc/FormattedMoney/American.html +255 -0
- data/doc/FormattedMoney/European.html +255 -0
- data/doc/FormattedMoney/NumberNotInFloatFormat.html +123 -0
- data/doc/FormattedMoney/NumberNotInIntegerFormat.html +123 -0
- data/doc/_index.html +162 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +328 -0
- data/doc/file.README.html +108 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +108 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +196 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/formatted-money.rb +166 -0
- data/test/test_all.rb +138 -0
- metadata +73 -0
data/test/test_all.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test-unit'
|
4
|
+
require 'formatted_money'
|
5
|
+
|
6
|
+
class TestFormattedMoney < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_conversion_to_cents
|
9
|
+
# Defaults to European style
|
10
|
+
assert_equal Integer(0), FormattedMoney.cents('0')
|
11
|
+
assert_equal Integer(0), FormattedMoney.cents('0,00')
|
12
|
+
assert_equal Integer(400056), FormattedMoney.cents('4.000,56')
|
13
|
+
assert_equal Integer(4200056), FormattedMoney.cents('42.000,56')
|
14
|
+
assert_equal Integer(139400056), FormattedMoney.cents('1.394.000,56')
|
15
|
+
assert_equal Integer(789999400056), FormattedMoney.cents('7.899.994.000,56')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_european_conversion_to_cents
|
19
|
+
assert_equal Integer(0), FormattedMoney::European.cents('0')
|
20
|
+
assert_equal Integer(0), FormattedMoney::European.cents('0,00')
|
21
|
+
assert_equal Integer(400056), FormattedMoney::European.cents('4.000,56')
|
22
|
+
assert_equal Integer(4200056), FormattedMoney::European.cents('42.000,56')
|
23
|
+
assert_equal Integer(139400056), FormattedMoney::European.cents('1.394.000,56')
|
24
|
+
assert_equal Integer(789999400056), FormattedMoney::European.cents('7.899.994.000,56')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_american_conversion_to_cents
|
28
|
+
assert_equal Integer(0), FormattedMoney::American.cents('0')
|
29
|
+
assert_equal Integer(0), FormattedMoney::American.cents('0.00')
|
30
|
+
assert_equal Integer(400056), FormattedMoney::American.cents('4,000.56')
|
31
|
+
assert_equal Integer(4200056), FormattedMoney::American.cents('42,000.56')
|
32
|
+
assert_equal Integer(139400056), FormattedMoney::American.cents('1,394,000.56')
|
33
|
+
assert_equal Integer(789999400056), FormattedMoney::American.cents('7,899,994,000.56')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_formatted_amount
|
37
|
+
# Defaults to European style
|
38
|
+
assert_equal '0,00', FormattedMoney.amount(Integer(0))
|
39
|
+
assert_equal '0,00', FormattedMoney.amount(Integer(00))
|
40
|
+
assert_equal '1.000,00', FormattedMoney.amount(Integer(100000))
|
41
|
+
assert_equal '1.234,56', FormattedMoney.amount(Integer(123456))
|
42
|
+
assert_equal '138.200,00', FormattedMoney.amount(Integer(13820000))
|
43
|
+
assert_equal '138.555.200,00', FormattedMoney.amount(Integer(13855520000))
|
44
|
+
assert_equal '26.897.200,00', FormattedMoney.amount(Integer(2689720000))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_formatted_amount_from_string
|
48
|
+
# Strings containing only numbers should be fine as well
|
49
|
+
assert_equal '0,00', FormattedMoney.amount(String('0'))
|
50
|
+
assert_equal '0,00', FormattedMoney.amount(String('00'))
|
51
|
+
assert_equal '138.555.200,00', FormattedMoney.amount('13855520000')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_europen_formatted_amount
|
55
|
+
assert_equal '0,00', FormattedMoney::European.amount(Integer(0))
|
56
|
+
assert_equal '0,00', FormattedMoney::European.amount(Integer(00))
|
57
|
+
assert_equal '1.000,00', FormattedMoney::European.amount(Integer(100000))
|
58
|
+
assert_equal '1.234,56', FormattedMoney::European.amount(Integer(123456))
|
59
|
+
assert_equal '138.200,00', FormattedMoney::European.amount(Integer(13820000))
|
60
|
+
assert_equal '138.555.200,00', FormattedMoney::European.amount(Integer(13855520000))
|
61
|
+
assert_equal '26.897.200,00', FormattedMoney::European.amount(Integer(2689720000))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_american_formatted_amount
|
65
|
+
assert_equal '0.00', FormattedMoney::American.amount(Integer(0))
|
66
|
+
assert_equal '0.00', FormattedMoney::American.amount(Integer(00))
|
67
|
+
assert_equal '1,000.00', FormattedMoney::American.amount(Integer(100000))
|
68
|
+
assert_equal '1,234.56', FormattedMoney::American.amount(Integer(123456))
|
69
|
+
assert_equal '138,200.00', FormattedMoney::American.amount(Integer(13820000))
|
70
|
+
assert_equal '138,555,200.00', FormattedMoney::American.amount(Integer(13855520000))
|
71
|
+
assert_equal '26,897,200.00', FormattedMoney::American.amount(Integer(2689720000))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_check_float
|
75
|
+
FormattedMoney.check_float('123,254')
|
76
|
+
FormattedMoney.check_float('3,254.456')
|
77
|
+
|
78
|
+
assert_raises (ArgumentError) {
|
79
|
+
FormattedMoney.check_float('123254d')
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_check_integer
|
84
|
+
FormattedMoney.check_integer('123254')
|
85
|
+
FormattedMoney.check_integer(123254)
|
86
|
+
|
87
|
+
assert_raises (ArgumentError) {
|
88
|
+
FormattedMoney.check_integer('123254d')
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_number_with_delimiter
|
93
|
+
assert_equal '1.000.000', FormattedMoney.number_with_delimiter('1000000','.')
|
94
|
+
assert_equal '400|000', FormattedMoney.number_with_delimiter('400000','|')
|
95
|
+
assert_equal '21,000,000,156', FormattedMoney.number_with_delimiter('21000000156',',')
|
96
|
+
|
97
|
+
assert_equal '1 000 000', FormattedMoney.number_with_delimiter('1000000',' ')
|
98
|
+
assert_equal '400 000', FormattedMoney.number_with_delimiter('400000',' ')
|
99
|
+
assert_equal '21 000 000 156', FormattedMoney.number_with_delimiter('21000000156',' ')
|
100
|
+
|
101
|
+
assert_equal '1.000.000', FormattedMoney.number_with_delimiter(1000000,'.')
|
102
|
+
assert_equal '400|000', FormattedMoney.number_with_delimiter(400000,'|')
|
103
|
+
assert_equal '21,000,000,156', FormattedMoney.number_with_delimiter(21000000156,',')
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_trim_leading_zeros
|
107
|
+
assert_equal '0', FormattedMoney.trim_leading_zeros('0')
|
108
|
+
assert_equal '525', FormattedMoney.trim_leading_zeros('0525')
|
109
|
+
assert_equal '2', FormattedMoney.trim_leading_zeros('0002')
|
110
|
+
assert_equal '300', FormattedMoney.trim_leading_zeros('0300')
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_separator_regex
|
114
|
+
FormattedMoney.escape_chars = ['.', '^', '$', '*']
|
115
|
+
|
116
|
+
assert_equal '\\.', FormattedMoney.separator_regex('.')
|
117
|
+
assert_equal ',', FormattedMoney.separator_regex(',')
|
118
|
+
|
119
|
+
FormattedMoney.escape_chars = []
|
120
|
+
|
121
|
+
assert_equal '.', FormattedMoney.separator_regex('.')
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_only_zeros
|
125
|
+
delimiter = '\.'
|
126
|
+
cents_separator = ','
|
127
|
+
|
128
|
+
assert_equal true, FormattedMoney.only_zeros?('0', delimiter, cents_separator)
|
129
|
+
assert_equal true, FormattedMoney.only_zeros?('0,0', delimiter, cents_separator)
|
130
|
+
assert_equal true, FormattedMoney.only_zeros?('0,00', delimiter, cents_separator)
|
131
|
+
assert_equal true, FormattedMoney.only_zeros?('0.00', delimiter, cents_separator)
|
132
|
+
assert_equal true, FormattedMoney.only_zeros?('0.000,0', delimiter, cents_separator)
|
133
|
+
assert_equal true, FormattedMoney.only_zeros?(',0', delimiter, cents_separator)
|
134
|
+
assert_equal false, FormattedMoney.only_zeros?('01', delimiter, cents_separator)
|
135
|
+
assert_equal false, FormattedMoney.only_zeros?('0|0', delimiter, cents_separator)
|
136
|
+
assert_equal false, FormattedMoney.only_zeros?('000500', delimiter, cents_separator)
|
137
|
+
end
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formatted-money
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josef Strzibny
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-19 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! " For all Rubyist that use Integer for storing money
|
15
|
+
values as cents.\n This is a dead simple gem for converting money
|
16
|
+
from user inputs to Integer values\n for storing and fast precise
|
17
|
+
calculations (and back). Does everything you need\n and nothing
|
18
|
+
else. Well tested.\n"
|
19
|
+
email: strzibny@strzibny.name
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- LICENSE
|
25
|
+
- Rakefile
|
26
|
+
- README.md
|
27
|
+
- doc/FormattedMoney.html
|
28
|
+
- doc/FormattedMoney/American.html
|
29
|
+
- doc/FormattedMoney/European.html
|
30
|
+
- doc/FormattedMoney/NumberNotInFloatFormat.html
|
31
|
+
- doc/FormattedMoney/NumberNotInIntegerFormat.html
|
32
|
+
- doc/_index.html
|
33
|
+
- doc/class_list.html
|
34
|
+
- doc/css/common.css
|
35
|
+
- doc/css/full_list.css
|
36
|
+
- doc/css/style.css
|
37
|
+
- doc/file.README.html
|
38
|
+
- doc/file_list.html
|
39
|
+
- doc/frames.html
|
40
|
+
- doc/index.html
|
41
|
+
- doc/js/app.js
|
42
|
+
- doc/js/full_list.js
|
43
|
+
- doc/js/jquery.js
|
44
|
+
- doc/method_list.html
|
45
|
+
- doc/top-level-namespace.html
|
46
|
+
- lib/formatted-money.rb
|
47
|
+
- test/test_all.rb
|
48
|
+
homepage: http://github.com/strzibny/formatted-money
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.9.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.6
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A dead simple library for converting human-readable money inputs to Integer
|
72
|
+
and back
|
73
|
+
test_files: []
|