Sha256: 5716d908a22ab0a69fc4de068977230471c2cb8c6df6baa16029caecde264a1f

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

class KeyVortex
  class Limitation
    attr_reader :type, :constraints

    def initialize(type, *constraints)
      @type = type
      @constraints = constraints
    end

    def add_constraint(*constraints)
      constraints.each do |constraint|
        unless constraint.is_a?(KeyVortex::Constraint::Base)
          raise KeyVortex::Error,
                "Not a constraint: #{constraint.class}"
        end
      end

      @constraints += constraints
    end

    def allows?(limitation)
      @constraints.all? do |constraint|
        limitation.accomodates?(constraint)
      end
    end

    def prohibits?(limitation)
      !allows?(limitation)
    end

    def accomodates?(constraint)
      @constraints.all? do |con|
        con.within?(constraint)
      end
    end

    def to_s
      "Limitation: #{@type}\n\t#{@constraints.join('\n\t')}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
key-vortex-0.1.3 lib/key_vortex/limitation.rb