money_parser 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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +101 -0
- data/VERSION +1 -0
- data/lib/money_parser.rb +40 -0
- data/money_parser.gemspec +14 -0
- data/spec/money_parser_spec.rb +1693 -0
- data/spec/spec_helper.rb +51 -0
- data/specification.rb +52 -0
- data/test/money_parser_spec.js +1357 -0
- data/vendor/assets/javascripts/parse_money.js +44 -0
- metadata +71 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'money_parser'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# some (optional) config here
|
8
|
+
end
|
9
|
+
|
10
|
+
def random_amount_of_spaces
|
11
|
+
' ' * rand(2)
|
12
|
+
end
|
13
|
+
|
14
|
+
def randomly_replace_zeros_by_o(string)
|
15
|
+
indexes = string.
|
16
|
+
each_char.
|
17
|
+
each_with_index.
|
18
|
+
to_a.
|
19
|
+
select{|l, idx| l == '0'}.
|
20
|
+
map{|_, idx| idx }
|
21
|
+
|
22
|
+
return nil if indexes.empty?
|
23
|
+
idx = indexes[rand(indexes.size)]
|
24
|
+
string.clone[idx] = 'O'
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_tests specs
|
28
|
+
code = ''
|
29
|
+
specs.inject([]) {|accu, pair|
|
30
|
+
|
31
|
+
money_string, result = pair
|
32
|
+
|
33
|
+
accu << [money_string, result]
|
34
|
+
accu << [random_amount_of_spaces + "-" + random_amount_of_spaces + money_string, result * -1]
|
35
|
+
|
36
|
+
tuple_with_o = [randomly_replace_zeros_by_o(money_string), result]
|
37
|
+
|
38
|
+
accu << tuple_with_o unless tuple_with_o[0].nil?
|
39
|
+
|
40
|
+
accu
|
41
|
+
}.each {|money_string, result|
|
42
|
+
|
43
|
+
code << %!
|
44
|
+
|
45
|
+
describe "\"#{money_string}\" should be parsed as #{result}" do
|
46
|
+
MoneyParser.parse("\"#{money_string}\").should == #{result}
|
47
|
+
end
|
48
|
+
!
|
49
|
+
}
|
50
|
+
code
|
51
|
+
end
|
data/specification.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
SPECIFICATION = [
|
2
|
+
["2000.01" , 2000.01],
|
3
|
+
["2000,01" , 2000.01],
|
4
|
+
["2000.1" , 2000.1],
|
5
|
+
["2000,1" , 2000.1],
|
6
|
+
["2000" , 2000.0],
|
7
|
+
[".01" , 0.01],
|
8
|
+
[",01" , 0.01],
|
9
|
+
["0.01" , 0.01],
|
10
|
+
["0,01" , 0.01],
|
11
|
+
[".1" , 0.1],
|
12
|
+
[",1" , 0.1],
|
13
|
+
["0.1" , 0.1],
|
14
|
+
["0,1" , 0.1],
|
15
|
+
["2,000.01" , 2000.01],
|
16
|
+
["2.000,01" , 2000.01],
|
17
|
+
["2 000.01" , 2000.01],
|
18
|
+
["2 000,01" , 2000.01],
|
19
|
+
["1,222,000.01", 1222000.01],
|
20
|
+
["1.222.000,01", 1222000.01],
|
21
|
+
["1 222 000.01", 1222000.01],
|
22
|
+
["1 222 000,01", 1222000.01],
|
23
|
+
["2,000.1" , 2000.1],
|
24
|
+
["2.000,1" , 2000.1],
|
25
|
+
["2 000.1" , 2000.1],
|
26
|
+
["2 000,1" , 2000.1],
|
27
|
+
["1,222,000.1" , 1222000.1],
|
28
|
+
["1.222.000,1" , 1222000.1],
|
29
|
+
["1 222 000.1" , 1222000.1],
|
30
|
+
["1 222 000,1" , 1222000.1],
|
31
|
+
["2,000.10" , 2000.1],
|
32
|
+
["2.000,10" , 2000.1],
|
33
|
+
["2 000.10" , 2000.1],
|
34
|
+
["2 000,10" , 2000.1],
|
35
|
+
["1,222,000.10", 1222000.1],
|
36
|
+
["1.222.000,10", 1222000.1],
|
37
|
+
["1 222 000.10", 1222000.1],
|
38
|
+
["1 222 000,10", 1222000.1],
|
39
|
+
["1 222 000" , 1222000.0],
|
40
|
+
["1 222 000" , 1222000.0],
|
41
|
+
["1,222,000" , 1222000.0],
|
42
|
+
["1.222.000" , 1222000.0],
|
43
|
+
["1 222 000" , 1222000.0],
|
44
|
+
["1 222 000" , 1222000.0],
|
45
|
+
["2,123" , 2123.0],
|
46
|
+
["2.123" , 2123.0],
|
47
|
+
["2,12" , 2.12],
|
48
|
+
["" , nil],
|
49
|
+
["1" , 1.0],
|
50
|
+
[" " , nil],
|
51
|
+
["hello" , nil]
|
52
|
+
]
|