money_parser 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17061821eaee57290483af05d265f37d828bc6d8
4
- data.tar.gz: 75952160c7f5bb973714f05b3c369e700d215631
3
+ metadata.gz: 212f37d8a4e447462e2056188bdd5fbba8f76492
4
+ data.tar.gz: df60980fac848ad0b3534d4c7a3d51a6553dba38
5
5
  SHA512:
6
- metadata.gz: 4cc1f9b20736daed4180792a83c98cfc7907cf6fc4d4c175dd2c53628e1e54a6d971ab5fdf52be5cad8ac2574f5a8ebc033db1c9a546eb30babfbc4ca1521985
7
- data.tar.gz: 4211f0e1172937021ee438575dd52bcf3ab6b77a0066919c2867aeaf90d89c418e3749e348849121f689c364917aaf7cb9fb83d4e0b0fa3e7be26cd5b57e4a9a
6
+ metadata.gz: 9e07831a478ad3ce79f50229a03f4cff8109542dd23151a743215e845c2e08e44ccc6caa914d12d9f312543e07ae6483f35943a1168e83d9a76e7c874e78ba52
7
+ data.tar.gz: 78de433426e0ce7e2daa9302d84b32d62be8fd64ff9c2cfd10582c4d0d2d40f369266ca93ccff18964d663b6b54fb0ad84e67c868523b5a084e171874f7ebee7
data/Rakefile CHANGED
@@ -40,7 +40,7 @@ def generate_tests specs
40
40
  ruby_code = "require 'spec_helper'\ndescribe MoneyParser do\n"
41
41
 
42
42
  js_code = "var assert = require(\"assert\")\n" +
43
- "var parseMoney = require('../vendor/assets/javascripts/parseMoney');\n\n" +
43
+ "var parseMoney = require('../vendor/assets/javascripts/parse_money');\n\n" +
44
44
  "describe('moneyParse', function(){\n"
45
45
 
46
46
 
@@ -54,14 +54,18 @@ def generate_tests specs
54
54
  accu << [random_amount_of_spaces + "-" + random_amount_of_spaces + money_string, result * -1, '(negative amount)']
55
55
  end
56
56
 
57
- tuple_with_o = [randomly_replace_zeros_by_o(money_string), result, '(with O instead of 0)']
57
+ if money_string.is_a?(String)
58
+ tuple_with_o = [randomly_replace_zeros_by_o(money_string), result, '(with O instead of 0)']
58
59
 
59
- accu << tuple_with_o unless tuple_with_o[0].nil?
60
+ accu << tuple_with_o unless tuple_with_o[0].nil?
61
+
62
+ accu << ['$' + money_string, result, '(with a dollar sign)']
63
+ accu << ['€' + money_string, result, '(with a euro sign)']
64
+ accu << ['£' + money_string, result, '(with a pound sign)']
65
+ accu << ['₤' + money_string, result, '(with a pound sign)']
66
+
67
+ end
60
68
 
61
- accu << ['$' + money_string, result, '(with a dollar sign)']
62
- accu << ['€' + money_string, result, '(with a euro sign)']
63
- accu << ['£' + money_string, result, '(with a pound sign)']
64
- accu << ['₤' + money_string, result, '(with a pound sign)']
65
69
 
66
70
  accu
67
71
  }.each {|money_string, result, comment|
@@ -71,15 +75,20 @@ def generate_tests specs
71
75
  else
72
76
  result.inspect
73
77
  end
78
+
79
+
80
+
74
81
  ruby_code << %!
75
82
 
76
- it '\"#{money_string}\" should be parsed as #{result.inspect} #{comment}' do
77
- MoneyParser.parse(\"#{money_string}\").should == #{expecting}
83
+ it '#{money_string.inspect} should be parsed as #{result.inspect} #{comment}' do
84
+ MoneyParser.parse(#{money_string.inspect}).should == #{expecting}
78
85
  end\n!
79
86
 
87
+ money_string_js = money_string.nil? ? 'null' : money_string.inspect
88
+
80
89
  js_code << %!
81
- it('\"#{money_string}\" should be parsed as #{nil_to_null(result.inspect)} #{comment}', function(){
82
- assert.equal(#{nil_to_null(result.inspect)}, parseMoney(\"#{money_string}\"));
90
+ it('#{money_string_js} should be parsed as #{nil_to_null(result.inspect)} #{comment}', function(){
91
+ assert.equal(#{nil_to_null(result.inspect)}, parseMoney(#{money_string_js}));
83
92
  });\n!
84
93
 
85
94
 
data/lib/money_parser.rb CHANGED
@@ -12,6 +12,8 @@ module MoneyParser
12
12
 
13
13
  def self.parse(money_string)
14
14
 
15
+ return nil if money_string.nil?
16
+
15
17
  cleaned_up = money_string.
16
18
  gsub(/\s+/,'').
17
19
  gsub(/(\d)o/i){$1 + '0'}.
data/money_parser.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'money_parser'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.homepage = 'https://github.com/leikind/money_parser'
5
- s.date = '2014-01-05'
5
+ s.date = '2014-03-02'
6
6
  s.summary = 'Tries to parse various crazy money formats'
7
7
  s.description = 'Tries to parse various crazy money formats'
8
8
  s.authors = ['Yuri Leikind']
@@ -2,18 +2,23 @@ require 'spec_helper'
2
2
  describe MoneyParser do
3
3
 
4
4
 
5
+ it 'nil should be parsed as nil ' do
6
+ MoneyParser.parse(nil).should == nil
7
+ end
8
+
9
+
5
10
  it '"2000.01" should be parsed as 2000.01 ' do
6
11
  MoneyParser.parse("2000.01").should == BigDecimal.new("2000.01")
7
12
  end
8
13
 
9
14
 
10
- it '" - 2000.01" should be parsed as -2000.01 (negative amount)' do
11
- MoneyParser.parse(" - 2000.01").should == BigDecimal.new("-2000.01")
15
+ it '"-2000.01" should be parsed as -2000.01 (negative amount)' do
16
+ MoneyParser.parse("-2000.01").should == BigDecimal.new("-2000.01")
12
17
  end
13
18
 
14
19
 
15
- it '"20o0.01" should be parsed as 2000.01 (with O instead of 0)' do
16
- MoneyParser.parse("20o0.01").should == BigDecimal.new("2000.01")
20
+ it '"2000.o1" should be parsed as 2000.01 (with O instead of 0)' do
21
+ MoneyParser.parse("2000.o1").should == BigDecimal.new("2000.01")
17
22
  end
18
23
 
19
24
 
@@ -42,8 +47,8 @@ describe MoneyParser do
42
47
  end
43
48
 
44
49
 
45
- it '"- 2000,01" should be parsed as -2000.01 (negative amount)' do
46
- MoneyParser.parse("- 2000,01").should == BigDecimal.new("-2000.01")
50
+ it '" - 2000,01" should be parsed as -2000.01 (negative amount)' do
51
+ MoneyParser.parse(" - 2000,01").should == BigDecimal.new("-2000.01")
47
52
  end
48
53
 
49
54
 
@@ -77,13 +82,13 @@ describe MoneyParser do
77
82
  end
78
83
 
79
84
 
80
- it '" - 2000.1" should be parsed as -2000.1 (negative amount)' do
81
- MoneyParser.parse(" - 2000.1").should == BigDecimal.new("-2000.1")
85
+ it '" -2000.1" should be parsed as -2000.1 (negative amount)' do
86
+ MoneyParser.parse(" -2000.1").should == BigDecimal.new("-2000.1")
82
87
  end
83
88
 
84
89
 
85
- it '"20o0.1" should be parsed as 2000.1 (with O instead of 0)' do
86
- MoneyParser.parse("20o0.1").should == BigDecimal.new("2000.1")
90
+ it '"2o00.1" should be parsed as 2000.1 (with O instead of 0)' do
91
+ MoneyParser.parse("2o00.1").should == BigDecimal.new("2000.1")
87
92
  end
88
93
 
89
94
 
@@ -112,13 +117,13 @@ describe MoneyParser do
112
117
  end
113
118
 
114
119
 
115
- it '" -2000,1" should be parsed as -2000.1 (negative amount)' do
116
- MoneyParser.parse(" -2000,1").should == BigDecimal.new("-2000.1")
120
+ it '"-2000,1" should be parsed as -2000.1 (negative amount)' do
121
+ MoneyParser.parse("-2000,1").should == BigDecimal.new("-2000.1")
117
122
  end
118
123
 
119
124
 
120
- it '"20o0,1" should be parsed as 2000.1 (with O instead of 0)' do
121
- MoneyParser.parse("20o0,1").should == BigDecimal.new("2000.1")
125
+ it '"2o00,1" should be parsed as 2000.1 (with O instead of 0)' do
126
+ MoneyParser.parse("2o00,1").should == BigDecimal.new("2000.1")
122
127
  end
123
128
 
124
129
 
@@ -147,8 +152,8 @@ describe MoneyParser do
147
152
  end
148
153
 
149
154
 
150
- it '" - 2000" should be parsed as -2000.0 (negative amount)' do
151
- MoneyParser.parse(" - 2000").should == BigDecimal.new("-2000.0")
155
+ it '"- 2000" should be parsed as -2000.0 (negative amount)' do
156
+ MoneyParser.parse("- 2000").should == BigDecimal.new("-2000.0")
152
157
  end
153
158
 
154
159
 
@@ -182,8 +187,8 @@ describe MoneyParser do
182
187
  end
183
188
 
184
189
 
185
- it '" - .01" should be parsed as -0.01 (negative amount)' do
186
- MoneyParser.parse(" - .01").should == BigDecimal.new("-0.01")
190
+ it '"- .01" should be parsed as -0.01 (negative amount)' do
191
+ MoneyParser.parse("- .01").should == BigDecimal.new("-0.01")
187
192
  end
188
193
 
189
194
 
@@ -217,8 +222,8 @@ describe MoneyParser do
217
222
  end
218
223
 
219
224
 
220
- it '"- ,01" should be parsed as -0.01 (negative amount)' do
221
- MoneyParser.parse("- ,01").should == BigDecimal.new("-0.01")
225
+ it '" -,01" should be parsed as -0.01 (negative amount)' do
226
+ MoneyParser.parse(" -,01").should == BigDecimal.new("-0.01")
222
227
  end
223
228
 
224
229
 
@@ -252,13 +257,13 @@ describe MoneyParser do
252
257
  end
253
258
 
254
259
 
255
- it '" - 0.01" should be parsed as -0.01 (negative amount)' do
256
- MoneyParser.parse(" - 0.01").should == BigDecimal.new("-0.01")
260
+ it '" -0.01" should be parsed as -0.01 (negative amount)' do
261
+ MoneyParser.parse(" -0.01").should == BigDecimal.new("-0.01")
257
262
  end
258
263
 
259
264
 
260
- it '"o.01" should be parsed as 0.01 (with O instead of 0)' do
261
- MoneyParser.parse("o.01").should == BigDecimal.new("0.01")
265
+ it '"0.o1" should be parsed as 0.01 (with O instead of 0)' do
266
+ MoneyParser.parse("0.o1").should == BigDecimal.new("0.01")
262
267
  end
263
268
 
264
269
 
@@ -287,8 +292,8 @@ describe MoneyParser do
287
292
  end
288
293
 
289
294
 
290
- it '" -0,01" should be parsed as -0.01 (negative amount)' do
291
- MoneyParser.parse(" -0,01").should == BigDecimal.new("-0.01")
295
+ it '" - 0,01" should be parsed as -0.01 (negative amount)' do
296
+ MoneyParser.parse(" - 0,01").should == BigDecimal.new("-0.01")
292
297
  end
293
298
 
294
299
 
@@ -322,8 +327,8 @@ describe MoneyParser do
322
327
  end
323
328
 
324
329
 
325
- it '" - .1" should be parsed as -0.1 (negative amount)' do
326
- MoneyParser.parse(" - .1").should == BigDecimal.new("-0.1")
330
+ it '"-.1" should be parsed as -0.1 (negative amount)' do
331
+ MoneyParser.parse("-.1").should == BigDecimal.new("-0.1")
327
332
  end
328
333
 
329
334
 
@@ -352,8 +357,8 @@ describe MoneyParser do
352
357
  end
353
358
 
354
359
 
355
- it '"- ,1" should be parsed as -0.1 (negative amount)' do
356
- MoneyParser.parse("- ,1").should == BigDecimal.new("-0.1")
360
+ it '" -,1" should be parsed as -0.1 (negative amount)' do
361
+ MoneyParser.parse(" -,1").should == BigDecimal.new("-0.1")
357
362
  end
358
363
 
359
364
 
@@ -382,8 +387,8 @@ describe MoneyParser do
382
387
  end
383
388
 
384
389
 
385
- it '" - 0.1" should be parsed as -0.1 (negative amount)' do
386
- MoneyParser.parse(" - 0.1").should == BigDecimal.new("-0.1")
390
+ it '" -0.1" should be parsed as -0.1 (negative amount)' do
391
+ MoneyParser.parse(" -0.1").should == BigDecimal.new("-0.1")
387
392
  end
388
393
 
389
394
 
@@ -487,8 +492,8 @@ describe MoneyParser do
487
492
  end
488
493
 
489
494
 
490
- it '" -2.000,01" should be parsed as -2000.01 (negative amount)' do
491
- MoneyParser.parse(" -2.000,01").should == BigDecimal.new("-2000.01")
495
+ it '" - 2.000,01" should be parsed as -2000.01 (negative amount)' do
496
+ MoneyParser.parse(" - 2.000,01").should == BigDecimal.new("-2000.01")
492
497
  end
493
498
 
494
499
 
@@ -522,13 +527,13 @@ describe MoneyParser do
522
527
  end
523
528
 
524
529
 
525
- it '"-2 000.01" should be parsed as -2000.01 (negative amount)' do
526
- MoneyParser.parse("-2 000.01").should == BigDecimal.new("-2000.01")
530
+ it '" - 2 000.01" should be parsed as -2000.01 (negative amount)' do
531
+ MoneyParser.parse(" - 2 000.01").should == BigDecimal.new("-2000.01")
527
532
  end
528
533
 
529
534
 
530
- it '"2 00o.01" should be parsed as 2000.01 (with O instead of 0)' do
531
- MoneyParser.parse("2 00o.01").should == BigDecimal.new("2000.01")
535
+ it '"2 0o0.01" should be parsed as 2000.01 (with O instead of 0)' do
536
+ MoneyParser.parse("2 0o0.01").should == BigDecimal.new("2000.01")
532
537
  end
533
538
 
534
539
 
@@ -557,8 +562,8 @@ describe MoneyParser do
557
562
  end
558
563
 
559
564
 
560
- it '"- 2 000,01" should be parsed as -2000.01 (negative amount)' do
561
- MoneyParser.parse("- 2 000,01").should == BigDecimal.new("-2000.01")
565
+ it '"-2 000,01" should be parsed as -2000.01 (negative amount)' do
566
+ MoneyParser.parse("-2 000,01").should == BigDecimal.new("-2000.01")
562
567
  end
563
568
 
564
569
 
@@ -592,13 +597,13 @@ describe MoneyParser do
592
597
  end
593
598
 
594
599
 
595
- it '" - 1,222,000.01" should be parsed as -1222000.01 (negative amount)' do
596
- MoneyParser.parse(" - 1,222,000.01").should == BigDecimal.new("-1222000.01")
600
+ it '"-1,222,000.01" should be parsed as -1222000.01 (negative amount)' do
601
+ MoneyParser.parse("-1,222,000.01").should == BigDecimal.new("-1222000.01")
597
602
  end
598
603
 
599
604
 
600
- it '"1,222,o00.01" should be parsed as 1222000.01 (with O instead of 0)' do
601
- MoneyParser.parse("1,222,o00.01").should == BigDecimal.new("1222000.01")
605
+ it '"1,222,0o0.01" should be parsed as 1222000.01 (with O instead of 0)' do
606
+ MoneyParser.parse("1,222,0o0.01").should == BigDecimal.new("1222000.01")
602
607
  end
603
608
 
604
609
 
@@ -627,8 +632,8 @@ describe MoneyParser do
627
632
  end
628
633
 
629
634
 
630
- it '"-1.222.000,01" should be parsed as -1222000.01 (negative amount)' do
631
- MoneyParser.parse("-1.222.000,01").should == BigDecimal.new("-1222000.01")
635
+ it '" - 1.222.000,01" should be parsed as -1222000.01 (negative amount)' do
636
+ MoneyParser.parse(" - 1.222.000,01").should == BigDecimal.new("-1222000.01")
632
637
  end
633
638
 
634
639
 
@@ -667,8 +672,8 @@ describe MoneyParser do
667
672
  end
668
673
 
669
674
 
670
- it '"1 222 000.o1" should be parsed as 1222000.01 (with O instead of 0)' do
671
- MoneyParser.parse("1 222 000.o1").should == BigDecimal.new("1222000.01")
675
+ it '"1 222 0o0.01" should be parsed as 1222000.01 (with O instead of 0)' do
676
+ MoneyParser.parse("1 222 0o0.01").should == BigDecimal.new("1222000.01")
672
677
  end
673
678
 
674
679
 
@@ -697,13 +702,13 @@ describe MoneyParser do
697
702
  end
698
703
 
699
704
 
700
- it '" - 1 222 000,01" should be parsed as -1222000.01 (negative amount)' do
701
- MoneyParser.parse(" - 1 222 000,01").should == BigDecimal.new("-1222000.01")
705
+ it '"- 1 222 000,01" should be parsed as -1222000.01 (negative amount)' do
706
+ MoneyParser.parse("- 1 222 000,01").should == BigDecimal.new("-1222000.01")
702
707
  end
703
708
 
704
709
 
705
- it '"1 222 000,o1" should be parsed as 1222000.01 (with O instead of 0)' do
706
- MoneyParser.parse("1 222 000,o1").should == BigDecimal.new("1222000.01")
710
+ it '"1 222 o00,01" should be parsed as 1222000.01 (with O instead of 0)' do
711
+ MoneyParser.parse("1 222 o00,01").should == BigDecimal.new("1222000.01")
707
712
  end
708
713
 
709
714
 
@@ -732,13 +737,13 @@ describe MoneyParser do
732
737
  end
733
738
 
734
739
 
735
- it '"-2,000.1" should be parsed as -2000.1 (negative amount)' do
736
- MoneyParser.parse("-2,000.1").should == BigDecimal.new("-2000.1")
740
+ it '" -2,000.1" should be parsed as -2000.1 (negative amount)' do
741
+ MoneyParser.parse(" -2,000.1").should == BigDecimal.new("-2000.1")
737
742
  end
738
743
 
739
744
 
740
- it '"2,0o0.1" should be parsed as 2000.1 (with O instead of 0)' do
741
- MoneyParser.parse("2,0o0.1").should == BigDecimal.new("2000.1")
745
+ it '"2,00o.1" should be parsed as 2000.1 (with O instead of 0)' do
746
+ MoneyParser.parse("2,00o.1").should == BigDecimal.new("2000.1")
742
747
  end
743
748
 
744
749
 
@@ -767,13 +772,13 @@ describe MoneyParser do
767
772
  end
768
773
 
769
774
 
770
- it '"-2.000,1" should be parsed as -2000.1 (negative amount)' do
771
- MoneyParser.parse("-2.000,1").should == BigDecimal.new("-2000.1")
775
+ it '"- 2.000,1" should be parsed as -2000.1 (negative amount)' do
776
+ MoneyParser.parse("- 2.000,1").should == BigDecimal.new("-2000.1")
772
777
  end
773
778
 
774
779
 
775
- it '"2.o00,1" should be parsed as 2000.1 (with O instead of 0)' do
776
- MoneyParser.parse("2.o00,1").should == BigDecimal.new("2000.1")
780
+ it '"2.00o,1" should be parsed as 2000.1 (with O instead of 0)' do
781
+ MoneyParser.parse("2.00o,1").should == BigDecimal.new("2000.1")
777
782
  end
778
783
 
779
784
 
@@ -807,8 +812,8 @@ describe MoneyParser do
807
812
  end
808
813
 
809
814
 
810
- it '"2 o00.1" should be parsed as 2000.1 (with O instead of 0)' do
811
- MoneyParser.parse("2 o00.1").should == BigDecimal.new("2000.1")
815
+ it '"2 0o0.1" should be parsed as 2000.1 (with O instead of 0)' do
816
+ MoneyParser.parse("2 0o0.1").should == BigDecimal.new("2000.1")
812
817
  end
813
818
 
814
819
 
@@ -837,13 +842,13 @@ describe MoneyParser do
837
842
  end
838
843
 
839
844
 
840
- it '" - 2 000,1" should be parsed as -2000.1 (negative amount)' do
841
- MoneyParser.parse(" - 2 000,1").should == BigDecimal.new("-2000.1")
845
+ it '"- 2 000,1" should be parsed as -2000.1 (negative amount)' do
846
+ MoneyParser.parse("- 2 000,1").should == BigDecimal.new("-2000.1")
842
847
  end
843
848
 
844
849
 
845
- it '"2 0o0,1" should be parsed as 2000.1 (with O instead of 0)' do
846
- MoneyParser.parse("2 0o0,1").should == BigDecimal.new("2000.1")
850
+ it '"2 o00,1" should be parsed as 2000.1 (with O instead of 0)' do
851
+ MoneyParser.parse("2 o00,1").should == BigDecimal.new("2000.1")
847
852
  end
848
853
 
849
854
 
@@ -872,8 +877,8 @@ describe MoneyParser do
872
877
  end
873
878
 
874
879
 
875
- it '"- 1,222,000.1" should be parsed as -1222000.1 (negative amount)' do
876
- MoneyParser.parse("- 1,222,000.1").should == BigDecimal.new("-1222000.1")
880
+ it '" -1,222,000.1" should be parsed as -1222000.1 (negative amount)' do
881
+ MoneyParser.parse(" -1,222,000.1").should == BigDecimal.new("-1222000.1")
877
882
  end
878
883
 
879
884
 
@@ -907,13 +912,13 @@ describe MoneyParser do
907
912
  end
908
913
 
909
914
 
910
- it '"- 1.222.000,1" should be parsed as -1222000.1 (negative amount)' do
911
- MoneyParser.parse("- 1.222.000,1").should == BigDecimal.new("-1222000.1")
915
+ it '"-1.222.000,1" should be parsed as -1222000.1 (negative amount)' do
916
+ MoneyParser.parse("-1.222.000,1").should == BigDecimal.new("-1222000.1")
912
917
  end
913
918
 
914
919
 
915
- it '"1.222.0o0,1" should be parsed as 1222000.1 (with O instead of 0)' do
916
- MoneyParser.parse("1.222.0o0,1").should == BigDecimal.new("1222000.1")
920
+ it '"1.222.o00,1" should be parsed as 1222000.1 (with O instead of 0)' do
921
+ MoneyParser.parse("1.222.o00,1").should == BigDecimal.new("1222000.1")
917
922
  end
918
923
 
919
924
 
@@ -982,8 +987,8 @@ describe MoneyParser do
982
987
  end
983
988
 
984
989
 
985
- it '"1 222 00o,1" should be parsed as 1222000.1 (with O instead of 0)' do
986
- MoneyParser.parse("1 222 00o,1").should == BigDecimal.new("1222000.1")
990
+ it '"1 222 o00,1" should be parsed as 1222000.1 (with O instead of 0)' do
991
+ MoneyParser.parse("1 222 o00,1").should == BigDecimal.new("1222000.1")
987
992
  end
988
993
 
989
994
 
@@ -1012,13 +1017,13 @@ describe MoneyParser do
1012
1017
  end
1013
1018
 
1014
1019
 
1015
- it '"- 2,000.10" should be parsed as -2000.1 (negative amount)' do
1016
- MoneyParser.parse("- 2,000.10").should == BigDecimal.new("-2000.1")
1020
+ it '" -2,000.10" should be parsed as -2000.1 (negative amount)' do
1021
+ MoneyParser.parse(" -2,000.10").should == BigDecimal.new("-2000.1")
1017
1022
  end
1018
1023
 
1019
1024
 
1020
- it '"2,000.1o" should be parsed as 2000.1 (with O instead of 0)' do
1021
- MoneyParser.parse("2,000.1o").should == BigDecimal.new("2000.1")
1025
+ it '"2,o00.10" should be parsed as 2000.1 (with O instead of 0)' do
1026
+ MoneyParser.parse("2,o00.10").should == BigDecimal.new("2000.1")
1022
1027
  end
1023
1028
 
1024
1029
 
@@ -1047,8 +1052,8 @@ describe MoneyParser do
1047
1052
  end
1048
1053
 
1049
1054
 
1050
- it '"- 2.000,10" should be parsed as -2000.1 (negative amount)' do
1051
- MoneyParser.parse("- 2.000,10").should == BigDecimal.new("-2000.1")
1055
+ it '"-2.000,10" should be parsed as -2000.1 (negative amount)' do
1056
+ MoneyParser.parse("-2.000,10").should == BigDecimal.new("-2000.1")
1052
1057
  end
1053
1058
 
1054
1059
 
@@ -1087,8 +1092,8 @@ describe MoneyParser do
1087
1092
  end
1088
1093
 
1089
1094
 
1090
- it '"2 o00.10" should be parsed as 2000.1 (with O instead of 0)' do
1091
- MoneyParser.parse("2 o00.10").should == BigDecimal.new("2000.1")
1095
+ it '"2 000.1o" should be parsed as 2000.1 (with O instead of 0)' do
1096
+ MoneyParser.parse("2 000.1o").should == BigDecimal.new("2000.1")
1092
1097
  end
1093
1098
 
1094
1099
 
@@ -1117,13 +1122,13 @@ describe MoneyParser do
1117
1122
  end
1118
1123
 
1119
1124
 
1120
- it '" - 2 000,10" should be parsed as -2000.1 (negative amount)' do
1121
- MoneyParser.parse(" - 2 000,10").should == BigDecimal.new("-2000.1")
1125
+ it '"-2 000,10" should be parsed as -2000.1 (negative amount)' do
1126
+ MoneyParser.parse("-2 000,10").should == BigDecimal.new("-2000.1")
1122
1127
  end
1123
1128
 
1124
1129
 
1125
- it '"2 000,1o" should be parsed as 2000.1 (with O instead of 0)' do
1126
- MoneyParser.parse("2 000,1o").should == BigDecimal.new("2000.1")
1130
+ it '"2 o00,10" should be parsed as 2000.1 (with O instead of 0)' do
1131
+ MoneyParser.parse("2 o00,10").should == BigDecimal.new("2000.1")
1127
1132
  end
1128
1133
 
1129
1134
 
@@ -1152,8 +1157,8 @@ describe MoneyParser do
1152
1157
  end
1153
1158
 
1154
1159
 
1155
- it '" - 1,222,000.10" should be parsed as -1222000.1 (negative amount)' do
1156
- MoneyParser.parse(" - 1,222,000.10").should == BigDecimal.new("-1222000.1")
1160
+ it '" -1,222,000.10" should be parsed as -1222000.1 (negative amount)' do
1161
+ MoneyParser.parse(" -1,222,000.10").should == BigDecimal.new("-1222000.1")
1157
1162
  end
1158
1163
 
1159
1164
 
@@ -1187,13 +1192,13 @@ describe MoneyParser do
1187
1192
  end
1188
1193
 
1189
1194
 
1190
- it '"-1.222.000,10" should be parsed as -1222000.1 (negative amount)' do
1191
- MoneyParser.parse("-1.222.000,10").should == BigDecimal.new("-1222000.1")
1195
+ it '" - 1.222.000,10" should be parsed as -1222000.1 (negative amount)' do
1196
+ MoneyParser.parse(" - 1.222.000,10").should == BigDecimal.new("-1222000.1")
1192
1197
  end
1193
1198
 
1194
1199
 
1195
- it '"1.222.00o,10" should be parsed as 1222000.1 (with O instead of 0)' do
1196
- MoneyParser.parse("1.222.00o,10").should == BigDecimal.new("1222000.1")
1200
+ it '"1.222.000,1o" should be parsed as 1222000.1 (with O instead of 0)' do
1201
+ MoneyParser.parse("1.222.000,1o").should == BigDecimal.new("1222000.1")
1197
1202
  end
1198
1203
 
1199
1204
 
@@ -1222,13 +1227,13 @@ describe MoneyParser do
1222
1227
  end
1223
1228
 
1224
1229
 
1225
- it '" -1 222 000.10" should be parsed as -1222000.1 (negative amount)' do
1226
- MoneyParser.parse(" -1 222 000.10").should == BigDecimal.new("-1222000.1")
1230
+ it '" - 1 222 000.10" should be parsed as -1222000.1 (negative amount)' do
1231
+ MoneyParser.parse(" - 1 222 000.10").should == BigDecimal.new("-1222000.1")
1227
1232
  end
1228
1233
 
1229
1234
 
1230
- it '"1 222 0o0.10" should be parsed as 1222000.1 (with O instead of 0)' do
1231
- MoneyParser.parse("1 222 0o0.10").should == BigDecimal.new("1222000.1")
1235
+ it '"1 222 000.1o" should be parsed as 1222000.1 (with O instead of 0)' do
1236
+ MoneyParser.parse("1 222 000.1o").should == BigDecimal.new("1222000.1")
1232
1237
  end
1233
1238
 
1234
1239
 
@@ -1257,13 +1262,13 @@ describe MoneyParser do
1257
1262
  end
1258
1263
 
1259
1264
 
1260
- it '" -1 222 000,10" should be parsed as -1222000.1 (negative amount)' do
1261
- MoneyParser.parse(" -1 222 000,10").should == BigDecimal.new("-1222000.1")
1265
+ it '" - 1 222 000,10" should be parsed as -1222000.1 (negative amount)' do
1266
+ MoneyParser.parse(" - 1 222 000,10").should == BigDecimal.new("-1222000.1")
1262
1267
  end
1263
1268
 
1264
1269
 
1265
- it '"1 222 o00,10" should be parsed as 1222000.1 (with O instead of 0)' do
1266
- MoneyParser.parse("1 222 o00,10").should == BigDecimal.new("1222000.1")
1270
+ it '"1 222 00o,10" should be parsed as 1222000.1 (with O instead of 0)' do
1271
+ MoneyParser.parse("1 222 00o,10").should == BigDecimal.new("1222000.1")
1267
1272
  end
1268
1273
 
1269
1274
 
@@ -1292,13 +1297,13 @@ describe MoneyParser do
1292
1297
  end
1293
1298
 
1294
1299
 
1295
- it '"-1 222 000" should be parsed as -1222000.0 (negative amount)' do
1296
- MoneyParser.parse("-1 222 000").should == BigDecimal.new("-1222000.0")
1300
+ it '" -1 222 000" should be parsed as -1222000.0 (negative amount)' do
1301
+ MoneyParser.parse(" -1 222 000").should == BigDecimal.new("-1222000.0")
1297
1302
  end
1298
1303
 
1299
1304
 
1300
- it '"1 222 o00" should be parsed as 1222000.0 (with O instead of 0)' do
1301
- MoneyParser.parse("1 222 o00").should == BigDecimal.new("1222000.0")
1305
+ it '"1 222 00o" should be parsed as 1222000.0 (with O instead of 0)' do
1306
+ MoneyParser.parse("1 222 00o").should == BigDecimal.new("1222000.0")
1302
1307
  end
1303
1308
 
1304
1309
 
@@ -1327,8 +1332,8 @@ describe MoneyParser do
1327
1332
  end
1328
1333
 
1329
1334
 
1330
- it '"- 1 222 000" should be parsed as -1222000.0 (negative amount)' do
1331
- MoneyParser.parse("- 1 222 000").should == BigDecimal.new("-1222000.0")
1335
+ it '" - 1 222 000" should be parsed as -1222000.0 (negative amount)' do
1336
+ MoneyParser.parse(" - 1 222 000").should == BigDecimal.new("-1222000.0")
1332
1337
  end
1333
1338
 
1334
1339
 
@@ -1397,13 +1402,13 @@ describe MoneyParser do
1397
1402
  end
1398
1403
 
1399
1404
 
1400
- it '" -1.222.000" should be parsed as -1222000.0 (negative amount)' do
1401
- MoneyParser.parse(" -1.222.000").should == BigDecimal.new("-1222000.0")
1405
+ it '"- 1.222.000" should be parsed as -1222000.0 (negative amount)' do
1406
+ MoneyParser.parse("- 1.222.000").should == BigDecimal.new("-1222000.0")
1402
1407
  end
1403
1408
 
1404
1409
 
1405
- it '"1.222.o00" should be parsed as 1222000.0 (with O instead of 0)' do
1406
- MoneyParser.parse("1.222.o00").should == BigDecimal.new("1222000.0")
1410
+ it '"1.222.00o" should be parsed as 1222000.0 (with O instead of 0)' do
1411
+ MoneyParser.parse("1.222.00o").should == BigDecimal.new("1222000.0")
1407
1412
  end
1408
1413
 
1409
1414
 
@@ -1432,13 +1437,13 @@ describe MoneyParser do
1432
1437
  end
1433
1438
 
1434
1439
 
1435
- it '" -1 222 000" should be parsed as -1222000.0 (negative amount)' do
1436
- MoneyParser.parse(" -1 222 000").should == BigDecimal.new("-1222000.0")
1440
+ it '"-1 222 000" should be parsed as -1222000.0 (negative amount)' do
1441
+ MoneyParser.parse("-1 222 000").should == BigDecimal.new("-1222000.0")
1437
1442
  end
1438
1443
 
1439
1444
 
1440
- it '"1 222 o00" should be parsed as 1222000.0 (with O instead of 0)' do
1441
- MoneyParser.parse("1 222 o00").should == BigDecimal.new("1222000.0")
1445
+ it '"1 222 0o0" should be parsed as 1222000.0 (with O instead of 0)' do
1446
+ MoneyParser.parse("1 222 0o0").should == BigDecimal.new("1222000.0")
1442
1447
  end
1443
1448
 
1444
1449
 
@@ -1472,8 +1477,8 @@ describe MoneyParser do
1472
1477
  end
1473
1478
 
1474
1479
 
1475
- it '"1 222 00o" should be parsed as 1222000.0 (with O instead of 0)' do
1476
- MoneyParser.parse("1 222 00o").should == BigDecimal.new("1222000.0")
1480
+ it '"1 222 0o0" should be parsed as 1222000.0 (with O instead of 0)' do
1481
+ MoneyParser.parse("1 222 0o0").should == BigDecimal.new("1222000.0")
1477
1482
  end
1478
1483
 
1479
1484
 
data/specification.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  SPECIFICATION = [
2
+ [nil , nil],
2
3
  ["2000.01" , 2000.01],
3
4
  ["2000,01" , 2000.01],
4
5
  ["2000.1" , 2000.1],
@@ -3,6 +3,10 @@ var parseMoney = require('../vendor/assets/javascripts/parse_money');
3
3
 
4
4
  describe('moneyParse', function(){
5
5
 
6
+ it('null should be parsed as null ', function(){
7
+ assert.equal(null, parseMoney(null));
8
+ });
9
+
6
10
  it('"2000.01" should be parsed as 2000.01 ', function(){
7
11
  assert.equal(2000.01, parseMoney("2000.01"));
8
12
  });
@@ -2,6 +2,10 @@
2
2
 
3
3
  parseMoney = function(moneyString){
4
4
 
5
+ if (moneyString === null || moneyString === null){
6
+ return null;
7
+ }
8
+
5
9
  var cleanedUp = moneyString.
6
10
  replace(/\s+/g,'').
7
11
  replace(/(\d)o/ig, function(match, p1, offset, string){
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Leikind
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-05 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec