Sha256: 2fad699bacd8b6e1c23813b60c73b451de897f4cb8adb72786e007a37adef6a3

Contents?: true

Size: 672 Bytes

Versions: 1

Compression:

Stored size: 672 Bytes

Contents

module CardsLib
  module IsSet
    class << self
      def verify(cards, rules = [:unique, :paired], specs = {})
        @max = specs.fetch(:max) {Float::INFINITY}
        @min = specs.fetch(:min) { 3 }
        rules.all? {|r| send(r, cards) } && (@min..@max).include?(cards.count)
      end

      private 
      def unique(cards)
        cards.combination(2).all? {|a,b| a != b }
      end

      def paired(cards)
        !(cards.inject(:paired?).is_a? NilCard)
      end
      
      def suited(cards)
        !(cards.inject(:suited?).is_a? NilCard)
      end

      def ordered(cards)
        !(cards.sort.inject(:ordered?).is_a? NilCard)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cards_lib-0.0.9 lib/cards_lib/is_set.rb