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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6302730a9554cb777109e4b35eaaee0da9963dbf
4
- data.tar.gz: ce9f0611782915a2aa0f788e2b9ad6a676c4dbaf
3
+ metadata.gz: bbeee1313b44a976a6f7244940b8b8f3b4101054
4
+ data.tar.gz: 147a0f56f5fec9af8d00861c233fe1bd607b5d6d
5
5
  SHA512:
6
- metadata.gz: 183e6584506fe0ff495c2d0d32ea6c3d208f16a9be9d01aec21d4d07f7d5c22218e29062aa09e82fa48d08e485ee8030f9b72d8f690ed3e2f3e83c98501362c3
7
- data.tar.gz: 57b26b992ced6c627aa6c346a6c495e91cbef9d3faef1fd9578790346ec8488cb147c2f85d927a09fbda71575c8a844c9b7179667f89a01e5a5f271b29eb0252
6
+ metadata.gz: 46456db1721dd08e2bad8fb665986ec4acfdeaaf8ea08eabd13909ba421c12a5d0d042ff7d8cfbd9b4a1a942df7608f3573043a6d49f407577df242feac10e78
7
+ data.tar.gz: 9c3edb5b6b7d885403dfa1b895d2331f0ab8c4206ce9aae3739e9ec7c2ad1406dcfbfde983fa2c3dd427ca79d93beb0c2bb289c43e9fd0ef8474dfd1498dea35
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Monetize
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
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 = compute_currency(input)
28
- if not assume_from_symbol
29
- computed_currency = input[/[A-Z]{2,3}/] || currency
30
- end
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.4.0"
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"
@@ -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.0.0
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-10-30 00:00:00.000000000 Z
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.4.0
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.4.0
26
+ version: 6.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement