Sha256: 0bb19c85ab0b541839099302b631bc32cde1750de09fcc0c2f0d044a304849a4

Contents?: true

Size: 1013 Bytes

Versions: 6

Compression:

Stored size: 1013 Bytes

Contents

module QueenCheck
  class << self
    def ElementsOf(name, elements = nil)
      if elements.nil? && !name.kind_of?(Array)
        return QueenCheck::ElementsOf.get_by_id(name)
      else
        return QueenCheck::ElementsOf.new(name, elements)
      end
    end
  end

  class ElementsOf
    @@instances = {}

    def self.get_by_id(id)
      return @@instances[id.to_s.to_sym]
    end

    attr_reader :elements, :name

    def arbitrary?; true; end

    def arbitrary(seed)
      @elements[rand(@elements.length)]
    end

    def initialize(name, elements = nil)
      if elements.nil? && name.kind_of?(Array)
        elements = name
        name = nil
      end

      raise ArgumentError, 'elements length require over 1' if !elements.respond_to?(:length) || elements.length < 0
      @elements = elements

      if name
        @name = name.to_s.to_sym
        @@instances[@name] = self
        QueenCheck::Arbitrary::Instance.collection["elements_of_#{@name}".to_sym] = self
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
queencheck-0.1.2 lib/queencheck/elements_of.rb
queencheck-0.1.1 lib/queencheck/elements_of.rb
queencheck-0.1.0 lib/queencheck/elements_of.rb
queencheck-0.0.2 lib/queencheck/elements_of.rb
queencheck-0.0.1 lib/queencheck/elements_of.rb
queencheck-0.0.0 lib/queencheck/elements_of.rb