Sha256: d25f7db4adefeacdc24e0832627c3c85b1128e6cc9973af127534547044ea605

Contents?: true

Size: 476 Bytes

Versions: 1

Compression:

Stored size: 476 Bytes

Contents

module Bridge
  class Trick
    attr_reader :cards, :trump, :suit

    def initialize(*args)
      options = args.pop if args.last.is_a?(Hash)
      @cards = args.flatten.map { |s| Bridge::Card.new(s.to_s) }
      @suit = @cards.first.suit
      @trump = options && options[:trump]
    end

    def winner
      winner_in_suit(@trump) || winner_in_suit(@suit)
    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.0.11 lib/bridge/trick.rb