Value: make objects Comparable
This commit is contained in:
parent
983861c1dc
commit
05cf6093d7
@ -1,5 +1,7 @@
|
||||
module Gnucash
|
||||
class Value
|
||||
include Comparable
|
||||
|
||||
attr_accessor :val
|
||||
|
||||
def initialize(val)
|
||||
@ -27,5 +29,9 @@ module Gnucash
|
||||
def to_s
|
||||
sprintf("%.02f", @val / 100.0)
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
@val <=> other.val
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -34,5 +34,11 @@ module Gnucash
|
||||
it "formats the number with two decimal places" do
|
||||
Value.new("1400/100").to_s.should == "14.00"
|
||||
end
|
||||
|
||||
it "supports comparisons between two Value objects" do
|
||||
Value.new("1234/100").should == Value.new(1234)
|
||||
(Value.new("89/100") < Value.new("100/100")).should be_true
|
||||
(Value.new("1234/100") > Value.new("222/100")).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user