monetize 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/monetize/version.rb +1 -1
- data/lib/monetize.rb +7 -6
- data/monetize.gemspec +1 -1
- data/spec/monetize_spec.rb +29 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbeee1313b44a976a6f7244940b8b8f3b4101054
|
4
|
+
data.tar.gz: 147a0f56f5fec9af8d00861c233fe1bd607b5d6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46456db1721dd08e2bad8fb665986ec4acfdeaaf8ea08eabd13909ba421c12a5d0d042ff7d8cfbd9b4a1a942df7608f3573043a6d49f407577df242feac10e78
|
7
|
+
data.tar.gz: 9c3edb5b6b7d885403dfa1b895d2331f0ab8c4206ce9aae3739e9ec7c2ad1406dcfbfde983fa2c3dd427ca79d93beb0c2bb289c43e9fd0ef8474dfd1498dea35
|
data/lib/monetize/version.rb
CHANGED
data/lib/monetize.rb
CHANGED
@@ -21,13 +21,14 @@ module Monetize
|
|
21
21
|
attr_accessor :assume_from_symbol
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.parse(input, currency = Money.default_currency)
|
24
|
+
def self.parse(input, currency = Money.default_currency, options = {})
|
25
25
|
input = input.to_s.strip
|
26
26
|
|
27
|
-
computed_currency =
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
computed_currency = if options.fetch(:assume_from_symbol) { assume_from_symbol }
|
28
|
+
compute_currency(input)
|
29
|
+
else
|
30
|
+
input[/[A-Z]{2,3}/]
|
31
|
+
end
|
31
32
|
|
32
33
|
currency = computed_currency || currency || Money.default_currency
|
33
34
|
currency = Money::Currency.wrap(currency)
|
@@ -169,6 +170,6 @@ module Monetize
|
|
169
170
|
end
|
170
171
|
|
171
172
|
def self.currency_symbol_regex
|
172
|
-
/\A(?<symbol>#{regex_safe_symbols})/
|
173
|
+
/\A[\+|\-]?(?<symbol>#{regex_safe_symbols})/
|
173
174
|
end
|
174
175
|
end
|
data/monetize.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "money", "~> 6.
|
21
|
+
spec.add_dependency "money", "~> 6.5.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
data/spec/monetize_spec.rb
CHANGED
@@ -53,6 +53,31 @@ describe Monetize do
|
|
53
53
|
it 'should assume default currency if not a recognised symbol' do
|
54
54
|
expect(Monetize.parse("L9.99")).to eq Money.new(999, 'USD')
|
55
55
|
end
|
56
|
+
|
57
|
+
it 'parses formatted inputs without currency detection when overridden' do
|
58
|
+
expect(Monetize.parse("£9.99", nil, assume_from_symbol: false)).to eq Money.new(999, 'USD')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'parses formatted inputs with minus sign and currency symbol' do
|
62
|
+
expect(Monetize.parse("-€9.99")).to eq Money.new(-999, 'EUR')
|
63
|
+
expect(Monetize.parse("-£9.99")).to eq Money.new(-999, 'GBP')
|
64
|
+
expect(Monetize.parse("-R$R9.99")).to eq Money.new(-999, 'BRL')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'parses formatted inputs with plus and GBP passed as symbol' do
|
68
|
+
expect(Monetize.parse("+€9.99")).to eq Money.new(999, 'EUR')
|
69
|
+
expect(Monetize.parse("+£9.99")).to eq Money.new(999, 'GBP')
|
70
|
+
expect(Monetize.parse("+R$R9.99")).to eq Money.new(999, 'BRL')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'parses formatted inputs with currency symbol and postfix minus sign' do
|
74
|
+
expect(Monetize.parse("€9.99-")).to eq Money.new(-999, 'EUR')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'parses formatted inputs with currency symbol and postfix plus sign' do
|
78
|
+
expect(Monetize.parse("€9.99+")).to eq Money.new(999, 'EUR')
|
79
|
+
end
|
80
|
+
|
56
81
|
end
|
57
82
|
|
58
83
|
context 'opted out' do
|
@@ -75,6 +100,10 @@ describe Monetize do
|
|
75
100
|
it "ignores the British Pounds Sterling symbol" do
|
76
101
|
expect(Monetize.parse("£9.99")).to eq Money.new(999, 'USD')
|
77
102
|
end
|
103
|
+
|
104
|
+
it 'parses formatted inputs with currency detection when overridden' do
|
105
|
+
expect(Monetize.parse("£9.99", nil, assume_from_symbol: true)).to eq Money.new(999, 'GBP')
|
106
|
+
end
|
78
107
|
end
|
79
108
|
|
80
109
|
it 'should opt out by default' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monetize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: 6.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.
|
26
|
+
version: 6.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|