Class: Braintree::AdvancedSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/braintree/advanced_search.rb

Defined Under Namespace

Classes: EndsWithNode, EqualityNode, IsNode, KeyValueNode, MultipleValueNode, MultipleValueOrTextNode, PartialMatchNode, RangeNode, SearchNode, TextNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdvancedSearch

Returns a new instance of AdvancedSearch.



148
149
150
# File 'lib/braintree/advanced_search.rb', line 148

def initialize
  @criteria = {}
end

Class Method Details

._create_field_accessors(fields, node_class) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/braintree/advanced_search.rb', line 139

def self._create_field_accessors(fields, node_class)
  fields.each do |field|
    define_method(field) do |*args|
      raise "An operator is required" unless args.empty?
      node_class.new(field, self)
    end
  end
end

.date_range_fields(*fields) ⇒ Object



131
132
133
# File 'lib/braintree/advanced_search.rb', line 131

def self.date_range_fields(*fields)
  _create_field_accessors(fields, DateRangeNode)
end

.ends_with_fields(*fields) ⇒ Object



135
136
137
# File 'lib/braintree/advanced_search.rb', line 135

def self.ends_with_fields(*fields)
  _create_field_accessors(fields, EndsWithNode)
end

.equality_fields(*fields) ⇒ Object



99
100
101
# File 'lib/braintree/advanced_search.rb', line 99

def self.equality_fields(*fields)
  _create_field_accessors(fields, EqualityNode)
end

.is_fields(*fields) ⇒ Object



103
104
105
# File 'lib/braintree/advanced_search.rb', line 103

def self.is_fields(*fields)
  _create_field_accessors(fields, IsNode)
end

.key_value_fields(*fields) ⇒ Object



123
124
125
# File 'lib/braintree/advanced_search.rb', line 123

def self.key_value_fields(*fields)
  _create_field_accessors(fields, KeyValueNode)
end

.multiple_value_field(field, options = {}) ⇒ Object



111
112
113
114
115
# File 'lib/braintree/advanced_search.rb', line 111

def self.multiple_value_field(field, options={})
  define_method(field) do
    MultipleValueNode.new(field, self, options)
  end
end

.multiple_value_or_text_field(field, options = {}) ⇒ Object



117
118
119
120
121
# File 'lib/braintree/advanced_search.rb', line 117

def self.multiple_value_or_text_field(field, options={})
  define_method(field) do
    MultipleValueOrTextNode.new(field, self, options)
  end
end

.partial_match_fields(*fields) ⇒ Object



107
108
109
# File 'lib/braintree/advanced_search.rb', line 107

def self.partial_match_fields(*fields)
  _create_field_accessors(fields, PartialMatchNode)
end

.range_fields(*fields) ⇒ Object



127
128
129
# File 'lib/braintree/advanced_search.rb', line 127

def self.range_fields(*fields)
  _create_field_accessors(fields, RangeNode)
end

.text_fields(*fields) ⇒ Object



95
96
97
# File 'lib/braintree/advanced_search.rb', line 95

def self.text_fields(*fields)
  _create_field_accessors(fields, TextNode)
end

Instance Method Details

#add_criteria(key, value) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/braintree/advanced_search.rb', line 152

def add_criteria(key, value)
  if @criteria[key].is_a?(Hash)
    @criteria[key].merge!(value)
  else
    @criteria[key] = value
  end
end

#to_hashObject



160
161
162
# File 'lib/braintree/advanced_search.rb', line 160

def to_hash
  @criteria
end