Class: Comet::SearchClause

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/models/search_clause.rb

Overview

SearchClause is a typed class wrapper around the underlying Comet Server API data structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSearchClause

Returns a new instance of SearchClause.



49
50
51
# File 'lib/comet/models/search_clause.rb', line 49

def initialize
  clear
end

Instance Attribute Details

#clause_childrenObject

If ClauseType is not SEARCHCLAUSE_RULE, the child rules will be applied according to the ClauseType (e.g. “and”/“or”)



44
45
46
# File 'lib/comet/models/search_clause.rb', line 44

def clause_children
  @clause_children
end

#clause_typeObject

One of the SEARCHCLAUSE_ constants (e.g. empty-string if this is a rule, or “and”/“or” if there are ClauseChildren)



18
19
20
# File 'lib/comet/models/search_clause.rb', line 18

def clause_type
  @clause_type
end

#rule_fieldObject

The field name to search. Check the specific API for more information about which fields are available for searching. For use with ClauseType = SEARCHCLAUSE_RULE.



23
24
25
# File 'lib/comet/models/search_clause.rb', line 23

def rule_field
  @rule_field
end

#rule_operatorObject

One of the SEARCHOPERATOR_ constants. The operator must match the type of the particular field. For use with ClauseType = SEARCHCLAUSE_RULE.



28
29
30
# File 'lib/comet/models/search_clause.rb', line 28

def rule_operator
  @rule_operator
end

#rule_valueObject

The value to compare the field against.

  • If the field is a string, any string is permissable.

  • If the field is an integer, the integer should be cast to a base-10 string. There is currently

no support for fractional or floating-point numbers.

  • If the field is a boolean, the following values can be used for true (“1”, “t”, “T”, “true”,

“TRUE”, “True”) and the following values can be used for false (“0”, “f”, “F”, “false”, “FALSE”, “False”). For use with ClauseType = SEARCHCLAUSE_RULE.



39
40
41
# File 'lib/comet/models/search_clause.rb', line 39

def rule_value
  @rule_value
end

#unknown_json_fieldsObject

Returns the value of attribute unknown_json_fields.



47
48
49
# File 'lib/comet/models/search_clause.rb', line 47

def unknown_json_fields
  @unknown_json_fields
end

Instance Method Details

#clearObject



53
54
55
56
57
58
59
60
# File 'lib/comet/models/search_clause.rb', line 53

def clear
  @clause_type = ''
  @rule_field = ''
  @rule_operator = ''
  @rule_value = ''
  @clause_children = []
  @unknown_json_fields = {}
end

#from_hash(obj) ⇒ Object

Parameters:

  • obj (Hash)

    The complete object as a Ruby hash

Raises:

  • (TypeError)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/comet/models/search_clause.rb', line 70

def from_hash(obj)
  raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash

  obj.each do |k, v|
    case k
    when 'ClauseType'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @clause_type = v
    when 'RuleField'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @rule_field = v
    when 'RuleOperator'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @rule_operator = v
    when 'RuleValue'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @rule_value = v
    when 'ClauseChildren'
      if v.nil?
        @clause_children = []
      else
        @clause_children = Array.new(v.length)
        v.each_with_index do |v1, i1|
          @clause_children[i1] = Comet::SearchClause.new
          @clause_children[i1].from_hash(v1)
        end
      end
    else
      @unknown_json_fields[k] = v
    end
  end
end

#from_json(json_string) ⇒ Object

Parameters:

  • json_string (String)

    The complete object in JSON format

Raises:

  • (TypeError)


63
64
65
66
67
# File 'lib/comet/models/search_clause.rb', line 63

def from_json(json_string)
  raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String

  from_hash(JSON.parse(json_string))
end

#to_hHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



124
125
126
# File 'lib/comet/models/search_clause.rb', line 124

def to_h
  to_hash
end

#to_hashHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/comet/models/search_clause.rb', line 108

def to_hash
  ret = {}
  ret['ClauseType'] = @clause_type
  ret['RuleField'] = @rule_field
  ret['RuleOperator'] = @rule_operator
  ret['RuleValue'] = @rule_value
  unless @clause_children.nil?
    ret['ClauseChildren'] = @clause_children
  end
  @unknown_json_fields.each do |k, v|
    ret[k] = v
  end
  ret
end

#to_json(options = {}) ⇒ String

Returns The complete object as a JSON string.

Returns:

  • (String)

    The complete object as a JSON string



129
130
131
# File 'lib/comet/models/search_clause.rb', line 129

def to_json(options = {})
  to_hash.to_json(options)
end