Sha256: 571e53ca9988ccef47dd7f74bf7d0a36bdc704e19f2cc7be21db0dd5f6388431

Contents?: true

Size: 481 Bytes

Versions: 1

Compression:

Stored size: 481 Bytes

Contents

module Bridge
  class Trick
    attr_reader :cards, :suit

    def initialize(*args)
      @cards = args.flatten.map { |c| Bridge::Card.new(c.to_s) }
      @suit = @cards.first.suit
    end

    def winner(trump = nil)
      winner_in_suit(trump) || winner_in_suit(suit)
    end

    def complete?
      cards.size == 4
    end

    def incomplete?
      !complete?
    end

    private

    def winner_in_suit(suit)
      cards.select { |c| c.suit == suit }.max
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bridge-0.2.0 lib/bridge/trick.rb