money_helper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/money_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
  require 'money'
5
5
 
6
6
  module MoneyHelper
7
-
7
+
8
8
  SYMBOL_ONLY = %w{USD GBP EUR MYR TRY} #don't use ISO code
9
9
  OK_SYMBOLS = %w{
10
10
  $ £ € ¥ 元 р. L ƒ ৳ P R$ K ₡ D ლ ₵ Q G ₹ Rp ₪ ₩ ₭ R RM ₨ ₮ դր. C$ ₦ TL ₲ ₱ T ฿ T$ m ₴ ₫ ៛
@@ -27,9 +27,10 @@ module MoneyHelper
27
27
  def self.money_to_text(amount, currency, number_only = false)
28
28
  return nil unless amount.present?
29
29
  currency = "USD" if currency.blank?
30
- symbol = Money::Currency.new(currency).symbol.strip
31
- include_symbol = !number_only && OK_SYMBOLS.include?(symbol)
32
- (number_only || SYMBOL_ONLY.include?(currency) ? "" : currency + " ") +
30
+ symbol = Money::Currency.new(currency).symbol
31
+ symbol.strip! if symbol.present?
32
+ include_symbol = !number_only && symbol.present? && OK_SYMBOLS.include?(symbol)
33
+ (number_only || SYMBOL_ONLY.include?(currency) ? "" : currency + " ") +
33
34
  Money.parse(amount.ceil, currency).format({
34
35
  no_cents: true,
35
36
  symbol_position: :before,
@@ -66,5 +67,5 @@ module MoneyHelper
66
67
  [ money_to_text(low, currency), money_to_text(high, currency, true) ].compact.join(delimiter)
67
68
  end
68
69
  end
69
-
70
+
70
71
  end
@@ -102,6 +102,9 @@ describe MoneyHelper do
102
102
  MoneyHelper.money_to_text(30000, "WST").should eql("WST T30,000")
103
103
  MoneyHelper.money_to_text(30000, "ZAR").should eql("ZAR R30,000")
104
104
  end
105
+ it "includes only ISO code for currencies that don't have a symbol" do
106
+ MoneyHelper.money_to_text(30000, "UZS").should eql("UZS 30,000")
107
+ end
105
108
  it "includes only ISO code for RTL symbols" do
106
109
  MoneyHelper.money_to_text(30000, "AFN").should eql("AFN 30,000")
107
110
  MoneyHelper.money_to_text(30000, "DZD").should eql("DZD 30,000")
@@ -127,12 +130,6 @@ describe MoneyHelper do
127
130
  MoneyHelper.money_to_text(30000, "").should eql("$30,000")
128
131
  MoneyHelper.money_to_text(30000, nil).should eql("$30,000")
129
132
  end
130
- it "returns only formatted numeral when number_only = true" do
131
- MoneyHelper.money_to_text(30000, "EUR", true).should eql("30.000")
132
- MoneyHelper.money_to_text(30000, "AUD", true).should eql("30,000")
133
- MoneyHelper.money_to_text(30000, "AMD", true).should eql("30,000")
134
- MoneyHelper.money_to_text(30000, "AFN", true).should eql("30,000")
135
- end
136
133
  it "returns only the formatted numeral when number_only = true" do
137
134
  MoneyHelper.money_to_text(30000, "EUR", true).should eql("30.000")
138
135
  MoneyHelper.money_to_text(30000, "AUD", true).should eql("30,000")
@@ -171,4 +168,4 @@ describe MoneyHelper do
171
168
  MoneyHelper.money_range_to_text(nil, nil, "USD").should be_nil
172
169
  end
173
170
  end
174
- end
171
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-16 00:00:00.000000000 Z
13
+ date: 2013-07-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: money
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  segments:
86
86
  - 0
87
- hash: -2590949666229956668
87
+ hash: 2615965141994932059
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: -2590949666229956668
96
+ hash: 2615965141994932059
97
97
  requirements: []
98
98
  rubyforge_project:
99
99
  rubygems_version: 1.8.25