money_parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,44 @@
|
|
1
|
+
// © Yuri Leikind 2014
|
2
|
+
|
3
|
+
parseMoney = function(moneyString){
|
4
|
+
|
5
|
+
var cleanedUp = moneyString.
|
6
|
+
replace(/\s+/g,'').
|
7
|
+
replace(/(\d)o/ig, function(match, p1, offset, string){
|
8
|
+
return p1 + '0';
|
9
|
+
}).
|
10
|
+
replace(/o(\d)/ig, function(match, p1, offset, string){
|
11
|
+
return '0' + p1;
|
12
|
+
}).
|
13
|
+
replace(/\s+/,'').
|
14
|
+
replace(/,/g, '.').
|
15
|
+
replace(/[^\d\.-]/g, '')
|
16
|
+
|
17
|
+
|
18
|
+
if (cleanedUp == ""){
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
|
22
|
+
var chunks = cleanedUp.split(".");
|
23
|
+
|
24
|
+
var normalized;
|
25
|
+
|
26
|
+
if (chunks.length == 1){
|
27
|
+
normalized = cleanedUp;
|
28
|
+
}else{
|
29
|
+
if (chunks[chunks.length - 1].length > 2){
|
30
|
+
normalized = chunks.join("")
|
31
|
+
}else{
|
32
|
+
normalized = chunks.slice(0, chunks.length - 1).join("") +
|
33
|
+
'.' + chunks[chunks.length - 1] ;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return parseFloat(normalized);
|
38
|
+
};
|
39
|
+
|
40
|
+
if (typeof module === 'undefined' ){
|
41
|
+
window['parseMoney'] = parseMoney;
|
42
|
+
}else{
|
43
|
+
module.exports = parseMoney;
|
44
|
+
}
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: money_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuri Leikind
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Tries to parse various crazy money formats
|
28
|
+
email: yuri.leikind@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- Gemfile
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- lib/money_parser.rb
|
41
|
+
- money_parser.gemspec
|
42
|
+
- spec/money_parser_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
- specification.rb
|
45
|
+
- test/money_parser_spec.js
|
46
|
+
- vendor/assets/javascripts/parse_money.js
|
47
|
+
homepage: https://github.com/leikind/money_parser
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Tries to parse various crazy money formats
|
71
|
+
test_files: []
|