lib/kosher/shipping.rb in kosher-0.2.24 vs lib/kosher/shipping.rb in kosher-0.3.0
- old
+ new
@@ -1,15 +1,26 @@
module Kosher
- class Shipping < Struct.new(:cents, :currency, :availability)
+ # Shipping details of an offer.
+ #
+ # Shipping costs something (or nothing) and is subject to availability.
+ class Shipping < Structure
+ key :cents, :type => Integer
+ key :currency
+ key :availability, :type => Structure
+
+ # Returns whether the item ships for free.
def free?
- cents.to_i == 0
+ cents == 0
end
+ # Returns true if the item is available to ship.
def kosher?
availability.kosher?
end
+ # The shipping cost.
def cost
- Money.new(cents.to_i, currency)
+ raise TypeError, "Can't render money" unless cents
+ Money.new(cents, currency)
end
end
end