Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: MrJoy/money
base: ecd7df2dae
...
head fork: MrJoy/money
compare: f1cdefb0ad
  • 12 commits
  • 4 files changed
  • 0 commit comments
  • 5 contributors
View
2  AUTHORS
@@ -1,5 +1,6 @@
Abhay Kumar
Alex Speller
+Andreas Loupasakis
Andrew White
banjerluke
Bodaniel Jeanes
@@ -13,6 +14,7 @@ Hongli Lai
Ilia Lobsanov
Jacob Atzen
James Cotterill
+James Hunt
Jean-Louis Giordano
Jell
Jeremy McNevin
View
2  CHANGELOG.md
@@ -25,6 +25,8 @@ high-precision values.
currencies (GH-155)
- Fix bug where rates exported to a file from VariableExchange leave the File
object open (GH-154)
+- Added Money#positive? and Money#negative? methods (GH-157)
+- Fix format function output for custom currencies (GH-156)
## 4.0.2
View
26 lib/money/money/arithmetic.rb
@@ -56,6 +56,32 @@ def <=>(other_money)
end
end
+ # Test if the amount is positive. Returns +true+ if the money amount is
+ # greater than 0, +false+ otherwise.
+ #
+ # @return [Boolean]
+ #
+ # @example
+ # Money.new(1).positive? #=> true
+ # Money.new(0).positive? #=> false
+ # Money.new(-1).positive? #=> false
+ def positive?
+ cents > 0
+ end
+
+ # Test if the amount is negative. Returns +true+ if the money amount is
+ # less than 0, +false+ otherwise.
+ #
+ # @return [Boolean]
+ #
+ # @example
+ # Money.new(-1).negative? #=> true
+ # Money.new(0).negative? #=> false
+ # Money.new(1).negative? #=> false
+ def negative?
+ cents < 0
+ end
+
# Returns a new Money object containing the sum of the two operands' monetary
# values. If +other_money+ has a different currency then its monetary value
# is automatically exchanged to this object's currency using +exchange_to+.
View
28 spec/money/arithmetic_spec.rb
@@ -164,6 +164,34 @@ def to_money
end
end
+ describe "#positive?" do
+ it "returns true if the amount is greater than 0" do
+ Money.new(1).should be_positive
+ end
+
+ it "returns false if the amount is 0" do
+ Money.new(0).should_not be_positive
+ end
+
+ it "returns false if the amount is negative" do
+ Money.new(-1).should_not be_positive
+ end
+ end
+
+ describe "#negative?" do
+ it "returns true if the amount is less than 0" do
+ Money.new(-1).should be_negative
+ end
+
+ it "returns false if the amount is 0" do
+ Money.new(0).should_not be_negative
+ end
+
+ it "returns false if the amount is greater than 0" do
+ Money.new(1).should_not be_negative
+ end
+ end
+
describe "#+" do
it "adds other amount to current amount (same currency)" do
(Money.new(10_00, "USD") + Money.new(90, "USD")).should == Money.new(10_90, "USD")

No commit comments for this range

Something went wrong with that request. Please try again.