1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Merge branch 'master' of git://github.com/evansenter/awesome_print into evansenter/master

This commit is contained in:
Mike Dvorkin 2012-09-03 21:02:12 -07:00
commit c7bdcd85e6
3 changed files with 15 additions and 9 deletions

View file

@ -196,12 +196,17 @@ module AwesomePrint
colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}", :dir)
end
# Format BigDecimal and Rational objects by convering them to Float.
# Format BigDecimal object.
#------------------------------------------------------------------------------
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
alias :awesome_rational :awesome_bigdecimal
# Format a method.
#------------------------------------------------------------------------------

View file

@ -43,6 +43,7 @@ module AwesomePrint
:keyword => :cyan,
:method => :purpleish,
:nilclass => :red,
:rational => :blue,
:string => :yellowish,
:struct => :pale,
:symbol => :cyanish,

View file

@ -479,14 +479,14 @@ EOS
#------------------------------------------------------------------------------
describe "BigDecimal and Rational" do
it "should present BigDecimal object as Float scalar" do
big = BigDecimal("2010.4")
big.ai(:plain => true).should == "2010.4"
it "should present BigDecimal object with arbitrary precision" do
big = BigDecimal("201020102010201020102010201020102010.4")
big.ai(:plain => true).should == "201020102010201020102010201020102010.4"
end
it "should present Rational object as Float scalar" do
rat = Rational(2010, 2)
rat.ai(:plain => true).should == "1005.0"
it "should present Rational object with arbitrary precision" do
rat = Rational(201020102010201020102010201020102010, 2)
rat.ai(:plain => true).should == "100510051005100510051005100510051005/1"
end
end