Class: NinjaModel::Predicate
- Inherits:
-
Object
- Object
- NinjaModel::Predicate
- Defined in:
- lib/ninja_model/predicate.rb
Constant Summary collapse
- PREDICATES =
[:eq, :ne, :gt, :gte, :lt, :lte, :in]
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#meth ⇒ Object
readonly
Returns the value of attribute meth.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #has_value? ⇒ Boolean
-
#initialize(attribute, meth, *args) ⇒ Predicate
constructor
A new instance of Predicate.
- #test(suspect) ⇒ Object
Constructor Details
#initialize(attribute, meth, *args) ⇒ Predicate
Returns a new instance of Predicate.
8 9 10 11 12 13 |
# File 'lib/ninja_model/predicate.rb', line 8 def initialize(attribute, meth, *args) @attribute = attribute @meth = meth @valued = !args.blank? @value = args.blank? ? nil : args.first end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
6 7 8 |
# File 'lib/ninja_model/predicate.rb', line 6 def attribute @attribute end |
#meth ⇒ Object (readonly)
Returns the value of attribute meth.
6 7 8 |
# File 'lib/ninja_model/predicate.rb', line 6 def meth @meth end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/ninja_model/predicate.rb', line 6 def value @value end |
Instance Method Details
#has_value? ⇒ Boolean
20 21 22 |
# File 'lib/ninja_model/predicate.rb', line 20 def has_value? @valued end |
#test(suspect) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ninja_model/predicate.rb', line 24 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 |