Sha256: 94186300c696d762bd0bd44c2f1e8ba676de79a77b0672d613e9c9fb3d50b549

Contents?: true

Size: 676 Bytes

Versions: 8

Compression:

Stored size: 676 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

      using Refinements::InjectWhile

      def paired(cards)
        cards.inject_while?(:paired?)
      end
      
      def suited(cards)
        cards.inject_while?(:suited?)
      end

      def ordered(cards)
        cards.sort.inject_while?(:ordered?)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cards_lib-0.2.4 lib/cards_lib/is_set.rb
cards_lib-0.2.3 lib/cards_lib/is_set.rb
cards_lib-0.2.2 lib/cards_lib/is_set.rb
cards_lib-0.2.1 lib/cards_lib/is_set.rb
cards_lib-0.2.0 lib/cards_lib/is_set.rb
cards_lib-0.1.2 lib/cards_lib/is_set.rb
cards_lib-0.1.1 lib/cards_lib/is_set.rb
cards_lib-0.1.0 lib/cards_lib/is_set.rb