exchange 1.0.2 → 1.0.4
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.
- data/lib/exchange/base.rb +1 -1
- data/lib/exchange/iso.rb +3 -3
- data/spec/exchange/iso_spec.rb +10 -0
- data/spec/exchange/money_spec.rb +8 -0
- metadata +2 -2
data/lib/exchange/base.rb
CHANGED
data/lib/exchange/iso.rb
CHANGED
@@ -118,14 +118,14 @@ module Exchange
|
|
118
118
|
string = format % amount
|
119
119
|
major, minor = string.split('.')
|
120
120
|
|
121
|
-
if separators[:major]
|
121
|
+
if separators[:major] && opts[:format] != :plain
|
122
122
|
major.reverse!
|
123
123
|
major.gsub!(/(\d{3})(?=.)/) { $1 + separators[:major] }
|
124
124
|
major.reverse!
|
125
125
|
end
|
126
126
|
|
127
|
-
string = minor ? major + (separators[:minor]
|
128
|
-
pre = [opts[:format]
|
127
|
+
string = minor ? major + (opts[:format] == :plain || !separators[:minor] ? '.' : separators[:minor]) + minor : major
|
128
|
+
pre = [[:amount, :plain].include?(opts[:format]) && '', opts[:format] == :symbol && definition[:symbol], currency.to_s.upcase + ' '].detect{|a| a.is_a?(String)}
|
129
129
|
|
130
130
|
"#{pre}#{string}"
|
131
131
|
end
|
data/spec/exchange/iso_spec.rb
CHANGED
@@ -800,6 +800,16 @@ describe "Exchange::ISO" do
|
|
800
800
|
subject.stringify(BigDecimal.new("23.0"), :clp, :format => :amount).should == "23"
|
801
801
|
end
|
802
802
|
end
|
803
|
+
context "plain amount" do
|
804
|
+
it "should not render the currency or separators" do
|
805
|
+
subject.stringify(BigDecimal.new("23.232524"), :tnd, :format => :plain).should == "23.233"
|
806
|
+
subject.stringify(BigDecimal.new("223423432343.232524"), :chf, :format => :plain).should == "223423432343.23"
|
807
|
+
subject.stringify(BigDecimal.new("23.232524"), :clp, :format => :plain).should == "23"
|
808
|
+
subject.stringify(BigDecimal.new("23.2"), :tnd, :format => :plain).should == "23.200"
|
809
|
+
subject.stringify(BigDecimal.new("25645645663.4"), :sar, :format => :plain).should == "25645645663.40"
|
810
|
+
subject.stringify(BigDecimal.new("23.0"), :clp, :format => :plain).should == "23"
|
811
|
+
end
|
812
|
+
end
|
803
813
|
context "symbol" do
|
804
814
|
context "with a symbol present" do
|
805
815
|
it "should render a symbol for the currency" do
|
data/spec/exchange/money_spec.rb
CHANGED
@@ -555,6 +555,14 @@ describe "Exchange::Money" do
|
|
555
555
|
Exchange::Money.new(23.4, :sar).to_s(:amount).should == "23.40"
|
556
556
|
Exchange::Money.new(23.0, :clp).to_s(:amount).should == "23"
|
557
557
|
end
|
558
|
+
it "should render only the currency amount and no separators if the argument amount is passed" do
|
559
|
+
Exchange::Money.new(2323.232524, :tnd).to_s(:plain).should == "2323.233"
|
560
|
+
Exchange::Money.new(2323.23252423, :sar).to_s(:plain).should == "2323.23"
|
561
|
+
Exchange::Money.new(2323.23252423, :clp).to_s(:plain).should == "2323"
|
562
|
+
Exchange::Money.new(23.2, :tnd).to_s(:plain).should == "23.200"
|
563
|
+
Exchange::Money.new(23.4, :sar).to_s(:plain).should == "23.40"
|
564
|
+
Exchange::Money.new(23.0, :clp).to_s(:plain).should == "23"
|
565
|
+
end
|
558
566
|
it "should render the currency with a symbol according to ISO 4217 Definitions" do
|
559
567
|
Exchange::Money.new(23.232524, :tnd).to_s(:symbol).should == "TND 23.233"
|
560
568
|
Exchange::Money.new(23.23252423, :sar).to_s(:symbol).should == "﷼23.23"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|