Sha256: bff5a3429d6ed6fd3854e4199140861f151ad9b6e328c6f368723b5a507295dc

Contents?: true

Size: 786 Bytes

Versions: 29

Compression:

Stored size: 786 Bytes

Contents

module NinjaModel
  class Predicate

    PREDICATES = [:eq, :ne, :gt, :gte, :lt, :lte, :in]

    attr_reader :attribute, :meth, :value

    def initialize(attribute, meth, *args)
      @attribute = attribute
      @meth = meth
      @valued = !args.blank?
      @value = args.blank? ? nil : args.first
    end

    def value=(value)
      @value = value
      @valued = true
    end

    def has_value?
      @valued
    end

    def test(suspect)
      case meth
      when :eq
        suspect.eql?(value)
      when :ne
        !suspect.eql?(value)
      when :gt
        suspect > value
      when :gte
        suspect >= value
      when :lt
        suspect < value
      when :lte
        suspect <= value
      when :in
        value.include?(suspect)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ninja-model-1.0.5 lib/ninja_model/predicate.rb
ninja-model-1.0.4 lib/ninja_model/predicate.rb
ninja-model-1.0.3 lib/ninja_model/predicate.rb
ninja-model-1.0.2 lib/ninja_model/predicate.rb
ninja-model-1.0.1 lib/ninja_model/predicate.rb
ninja-model-1.0.0 lib/ninja_model/predicate.rb
ninja-model-0.9.6 lib/ninja_model/predicate.rb
ninja-model-0.9.5 lib/ninja_model/predicate.rb
ninja-model-0.9.4 lib/ninja_model/predicate.rb
ninja-model-0.9.3 lib/ninja_model/predicate.rb
ninja-model-0.9.2 lib/ninja_model/predicate.rb
ninja-model-0.9.1 lib/ninja_model/predicate.rb
ninja-model-0.9.0 lib/ninja_model/predicate.rb
ninja-model-0.8.1 lib/ninja_model/predicate.rb
ninja-model-0.8.0 lib/ninja_model/predicate.rb
ninja-model-0.7.3 lib/ninja_model/predicate.rb
ninja-model-0.7.2 lib/ninja_model/predicate.rb
ninja-model-0.7.1 lib/ninja_model/predicate.rb
ninja-model-0.7.0 lib/ninja_model/predicate.rb
ninja-model-0.6.2 lib/ninja_model/predicate.rb