Class: Omise::SearchScope

Inherits:
Object
  • Object
show all
Defined in:
lib/omise/search_scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, options = {}) ⇒ SearchScope

Returns a new instance of SearchScope.



5
6
7
8
9
10
11
# File 'lib/omise/search_scope.rb', line 5

def initialize(scope, options = {})
  @scope             = scope.to_s
  @filters           = options.delete(:filters) { Hash.new }
  @order             = options.delete(:order)
  @page              = options.delete(:page)
  @query             = options.delete(:query)
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



13
14
15
# File 'lib/omise/search_scope.rb', line 13

def scope
  @scope
end

Instance Method Details

#executeObject



32
33
34
# File 'lib/omise/search_scope.rb', line 32

def execute
  Search.execute(to_attributes)
end

#filter(filters = {}) ⇒ Object



15
16
17
# File 'lib/omise/search_scope.rb', line 15

def filter(filters = {})
  renew(filters: @filters.merge(filters))
end

#order(order) ⇒ Object



24
25
26
# File 'lib/omise/search_scope.rb', line 24

def order(order)
  renew(order: order)
end

#page(number) ⇒ Object



28
29
30
# File 'lib/omise/search_scope.rb', line 28

def page(number)
  renew(page: number)
end

#query(terms = nil) ⇒ Object



19
20
21
22
# File 'lib/omise/search_scope.rb', line 19

def query(terms = nil)
  return self if !terms
  renew(query: terms)
end

#to_attributesObject



36
37
38
39
40
41
42
43
44
# File 'lib/omise/search_scope.rb', line 36

def to_attributes
  {}.tap do |a|
    a[:scope]   = @scope
    a[:filters] = @filters if @filters.any?
    a[:query]   = @query if @query
    a[:order]   = @order if @order
    a[:page]    = @page if @page
  end
end