mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Patching awesome_bigdecimal to not have lossy precision.
This commit is contained in:
parent
fea9567eb4
commit
bd032ca03b
4 changed files with 16 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
awesome_print (1.0.0)
|
awesome_print (1.0.2)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
|
|
|
@ -189,12 +189,17 @@ module AwesomePrint
|
||||||
colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}", :dir)
|
colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}", :dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Format BigDecimal and Rational objects by convering them to Float.
|
# Format BigDecimal object.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome_bigdecimal(n)
|
def awesome_bigdecimal(n)
|
||||||
colorize(n.to_f.inspect, :bigdecimal)
|
colorize(n.to_s("F"), :bigdecimal)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Format Rational object.
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
def awesome_rational(n)
|
||||||
|
colorize(n.to_s, :rational)
|
||||||
end
|
end
|
||||||
alias :awesome_rational :awesome_bigdecimal
|
|
||||||
|
|
||||||
# Format a method.
|
# Format a method.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
|
@ -43,6 +43,7 @@ module AwesomePrint
|
||||||
:keyword => :cyan,
|
:keyword => :cyan,
|
||||||
:method => :purpleish,
|
:method => :purpleish,
|
||||||
:nilclass => :red,
|
:nilclass => :red,
|
||||||
|
:rational => :blue,
|
||||||
:string => :yellowish,
|
:string => :yellowish,
|
||||||
:struct => :pale,
|
:struct => :pale,
|
||||||
:symbol => :cyanish,
|
:symbol => :cyanish,
|
||||||
|
|
|
@ -479,14 +479,14 @@ EOS
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
describe "BigDecimal and Rational" do
|
describe "BigDecimal and Rational" do
|
||||||
it "should present BigDecimal object as Float scalar" do
|
it "should present BigDecimal object with arbitrary precision" do
|
||||||
big = BigDecimal("2010.4")
|
big = BigDecimal("201020102010201020102010201020102010.4")
|
||||||
big.ai(:plain => true).should == "2010.4"
|
big.ai(:plain => true).should == "201020102010201020102010201020102010.4"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should present Rational object as Float scalar" do
|
it "should present Rational object with arbitrary precision" do
|
||||||
rat = Rational(2010, 2)
|
rat = Rational(201020102010201020102010201020102010, 2)
|
||||||
rat.ai(:plain => true).should == "1005.0"
|
rat.ai(:plain => true).should == "100510051005100510051005100510051005/1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue