From d72de51977a0390ca319aebda6420f84ec5659e8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 19 Aug 2013 23:26:01 -0400 Subject: [PATCH] allow negating Value objects --- lib/gnucash/value.rb | 5 +++++ spec/gnucash/value_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/gnucash/value.rb b/lib/gnucash/value.rb index fa8b68d..d343b3a 100644 --- a/lib/gnucash/value.rb +++ b/lib/gnucash/value.rb @@ -59,6 +59,11 @@ module Gnucash end end + # Negate a Value + def -@ + Value.new(-@val, @div) + end + # Multiply a Value object # +other+ should be a Numeric def *(other) diff --git a/spec/gnucash/value_spec.rb b/spec/gnucash/value_spec.rb index 8d9a6f6..1a92e80 100644 --- a/spec/gnucash/value_spec.rb +++ b/spec/gnucash/value_spec.rb @@ -51,6 +51,12 @@ module Gnucash c.should == 1.1 end + it "allows negating a Value object" do + a = Value.new("123/100") + b = -a + b.to_s.should == "-1.23" + end + it "allows multiplying a Value by a Numeric" do a = Value.new("100/100") b = 12