Class: Comet::SearchClause
- Inherits:
-
Object
- Object
- Comet::SearchClause
- 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
-
#clause_children ⇒ Object
If ClauseType is not SEARCHCLAUSE_RULE, the child rules will be applied according to the ClauseType (e.g. “and”/“or”).
-
#clause_type ⇒ Object
One of the SEARCHCLAUSE_ constants (e.g. empty-string if this is a rule, or “and”/“or” if there are ClauseChildren).
-
#rule_field ⇒ Object
The field name to search.
-
#rule_operator ⇒ Object
One of the SEARCHOPERATOR_ constants.
-
#rule_value ⇒ Object
The value to compare the field against.
-
#unknown_json_fields ⇒ Object
Returns the value of attribute unknown_json_fields.
Instance Method Summary collapse
- #clear ⇒ Object
- #from_hash(obj) ⇒ Object
- #from_json(json_string) ⇒ Object
-
#initialize ⇒ SearchClause
constructor
A new instance of SearchClause.
-
#to_h ⇒ Hash
The complete object as a Ruby hash.
-
#to_hash ⇒ Hash
The complete object as a Ruby hash.
-
#to_json(options = {}) ⇒ String
The complete object as a JSON string.
Constructor Details
#initialize ⇒ SearchClause
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_children ⇒ Object
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_type ⇒ Object
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_field ⇒ Object
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_operator ⇒ Object
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_value ⇒ Object
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_fields ⇒ Object
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
#clear ⇒ Object
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
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
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_h ⇒ Hash
Returns 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_hash ⇒ Hash
Returns 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.
129 130 131 |
# File 'lib/comet/models/search_clause.rb', line 129 def to_json( = {}) to_hash.to_json() end |