Class: JSS::Criteriable::Criterion
- Includes:
- Comparable
- Defined in:
- lib/jss/api_object/criteriable/criterion.rb,
lib/jss.rb
Overview
This class defines a single criterion used in advanced searches and smart groups throughout the JSS module.
They are used within Criteria instances which store an array of these objects and provides methods for working with them as a group.
The classes that mix-in JSS::Criteriable each have a :criteria attribute which holds one Criteria
See JSS::Criteriable for examples
Constant Summary collapse
- SEARCH_TYPES =
These are the available search-types for building criteria
[ "is", "is not", "like", "not like", "has", "does not have", "more than", "less than", "before (yyyy-mm-dd)", "after (yyyy-mm-dd)", "more than x days ago", "less than x days ago", "in more than x days", "in less than x days", "member of", "not member of", "current", "not current" ]
- AND_OR =
the acceptable symboles for and/or
[:and, :or]
Instance Attribute Summary collapse
-
#and_or ⇒ Symbol
:and or :or - the and_or value for associating this criterion with the previous one.
-
#name ⇒ String
The name of the field being searched.
-
#priority ⇒ Integer
Zero-based index of this criterion within an array of criteria used for an advanced search or smart group.
-
#search_type ⇒ String
The comparator between the field and the value, must be one of SEARCH_TYPES.
-
#value ⇒ String
The value being searched for in the field named by :name.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Comparison - allows the Comparable module to do its work.
-
#initialize(args = {}) ⇒ Criterion
constructor
A new instance of Criterion.
-
#rest_xml ⇒ REXML::Element
private
The xml element for the criterion, to be embeded in that of a Criteria instance.
-
#signature ⇒ String
All our values except priority joined together for comparing this Criterion to another for equality and order.
Constructor Details
#initialize(args = {}) ⇒ Criterion
:priority is maintained by the JSS::Criteriable::Criteria object holding this instance
Returns a new instance of Criterion.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 122 def initialize(args = {}) @priority = args[:priority] @and_or = (args[:and_or].downcase.to_sym if args[:and_or]) || :and raise JSS::InvalidDataError, ":and_or must be 'and' or 'or'." unless AND_OR.include? @and_or @name = args[:name] if args[:search_type] raise JSS::InvalidDataError, "Invalid :search_type" unless SEARCH_TYPES.include? args[:search_type] @search_type = args[:search_type] end @value = args[:value] end |
Instance Attribute Details
#and_or ⇒ Symbol
Returns :and or :or - the and_or value for associating this criterion with the previous one.
101 102 103 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 101 def and_or @and_or end |
#name ⇒ String
Returns the name of the field being searched.
104 105 106 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 104 def name @name end |
#priority ⇒ Integer
Returns zero-based index of this criterion within an array of criteria used for an advanced search or smart group. This is maintained automaticaly by the enclosing Criteria object.
98 99 100 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 98 def priority @priority end |
#search_type ⇒ String
Returns the comparator between the field and the value, must be one of SEARCH_TYPES.
108 109 110 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 108 def search_type @search_type end |
#value ⇒ String
Returns the value being searched for in the field named by :name.
111 112 113 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 111 def value @value end |
Instance Method Details
#<=>(other) ⇒ Integer
Comparison - allows the Comparable module to do its work
203 204 205 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 203 def <=>(other) self.signature <=> other.signature end |
#rest_xml ⇒ REXML::Element
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
For this class, rest_xml can’t be a private method.
Returns The xml element for the criterion, to be embeded in that of a Criteria instance.
215 216 217 218 219 220 221 222 223 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 215 def rest_xml crn = REXML::Element.new 'criterion' crn.add_element('priority').text = @priority crn.add_element('and_or').text = @and_or crn.add_element('name').text = @name crn.add_element('search_type').text = @search_type crn.add_element('value').text = @value return crn end |
#signature ⇒ String
Returns All our values except priority joined together for comparing this Criterion to another for equality and order.
191 192 193 |
# File 'lib/jss/api_object/criteriable/criterion.rb', line 191 def signature [@and_or, @name, @search_type, @value].join "," end |