Sha256: 28593bbcbc362ec59ff8652b38ea162849af038cc2521b2033dcc979cab97312

Contents?: true

Size: 655 Bytes

Versions: 13

Compression:

Stored size: 655 Bytes

Contents

# frozen_string_literal: true

class Shaped::Shapes::Any < Shaped::Shape
  def initialize(*shape_descriptions)
    validation_options = shape_descriptions.extract_options!
    if shape_descriptions.size <= 1
      raise(Shaped::InvalidShapeDescription, <<~ERROR.squish)
        A #{self.class} description must be a list of two or more shape descriptions.
      ERROR
    end

    @shapes =
      shape_descriptions.map do |description|
        Shaped::Shape(description, validation_options)
      end
  end

  def matched_by?(object)
    @shapes.any? { |shape| shape.matched_by?(object) }
  end

  def to_s
    @shapes.map(&:to_s).join(' OR ')
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shaped-0.14.0 lib/shaped/shapes/any.rb
shaped-0.13.0 lib/shaped/shapes/any.rb
shaped-0.12.0 lib/shaped/shapes/any.rb
shaped-0.11.0 lib/shaped/shapes/any.rb
shaped-0.10.0 lib/shaped/shapes/any.rb
shaped-0.9.1 lib/shaped/shapes/any.rb
shaped-0.9.0 lib/shaped/shapes/any.rb
shaped-0.8.2 lib/shaped/shapes/any.rb
shaped-0.8.0 lib/shaped/shapes/any.rb
shaped-0.7.3 lib/shaped/shapes/any.rb
shaped-0.7.2 lib/shaped/shapes/any.rb
shaped-0.7.1 lib/shaped/shapes/any.rb
shaped-0.7.0 lib/shaped/shapes/any.rb