Class: JSS::Criteriable::Criterion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/jss-api/api_object/criteriable/criterion.rb,
lib/jss-api.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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Criterion

Note:

:priority is maintained by the JSS::Criteriable::Criteria object holding this instance

Returns a new instance of Criterion.

Parameters:

  • args (Hash) (defaults to: {})

    a hash of settings for the new criterion

Options Hash (args):

  • :and_or (String, Symbol)

    :and, or :or. How should this criterion be join with its predecessor?

  • :name (String)

    the name of a Criterion as is visible in the JSS webapp.

  • :search_type (String)

    one of SEARCH_TYPES, the comparison between the stored value and :value

  • :value (String)

    the value to compare with that stored for :name



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 121

def initialize(args = {})

  @priority = args[:priority]

  if args[:and_or]
    @and_or = args[:and_or].to_sym
    raise JSS::InvalidDataError, ":and_or must be 'and' or 'or'." unless AND_OR.include? @and_or
  end

  @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_orSymbol

Returns :and or :or - the and_or value for associating this criterion with the previous one.

Returns:

  • (Symbol)

    :and or :or - the and_or value for associating this criterion with the previous one



100
101
102
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 100

def and_or
  @and_or
end

#nameString

Returns the name of the field being searched.

Returns:

  • (String)

    the name of the field being searched



103
104
105
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 103

def name
  @name
end

#priorityInteger

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.

Returns:

  • (Integer)

    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



97
98
99
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 97

def priority
  @priority
end

#search_typeString

Returns the comparator between the field and the value, must be one of SEARCH_TYPES.

Returns:

  • (String)

    the comparator between the field and the value, must be one of SEARCH_TYPES

See Also:



107
108
109
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 107

def search_type
  @search_type
end

#valueString

Returns the value being searched for in the field named by :name.

Returns:

  • (String)

    the value being searched for in the field named by :name



110
111
112
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 110

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Integer

Comparison - allows the Comparable module to do its work

Returns:

  • (Integer)

    -1, 0, or 1

See Also:

  • Comparable


204
205
206
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 204

def <=>(other)
  self.signature <=> other.signature
end

#rest_xmlREXML::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.

Note:

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.

Returns:

  • (REXML::Element)

    The xml element for the criterion, to be embeded in that of a Criteria instance



216
217
218
219
220
221
222
223
224
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 216

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

#signatureString

Returns All our values except priority joined together for comparing this Criterion to another for equality and order.

Returns:

  • (String)

    All our values except priority joined together for comparing this Criterion to another for equality and order

See Also:



192
193
194
# File 'lib/jss-api/api_object/criteriable/criterion.rb', line 192

def signature
  [@and_or, @name, @search_type, @value].join ","
end