Sha256: 4e1df3656c2339f98684eca88e952d867d05fd80c2f57c60a397d1d5b50428e5

Contents?: true

Size: 620 Bytes

Versions: 2

Compression:

Stored size: 620 Bytes

Contents

require 'kosher/base'
require 'kosher/price'

require 'kosher/seller'
require 'kosher/shipping'
require 'kosher/unit'
require 'kosher/venue'

module Kosher
  class Offer < Structure
    include Comparable

    key :id
    key :seller
    key :shipping
    key :unit
    key :venue_id, Integer

    def <=>(other)
      if kosher? != other.kosher?
        kosher? ? -1 : 1
      else
        price <=> other.price
      end
    end

    def kosher?
      [seller, shipping, unit].all?(&:kosher?)
    end

    def price
      unit.price + shipping.price
    end

    def venue
      Venue.find(venue_id)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kosher-0.11.1 lib/kosher/offer.rb
kosher-0.11.0 lib/kosher/offer.rb