Class: Omise::SearchScope
- Inherits:
-
Object
- Object
- Omise::SearchScope
- Defined in:
- lib/omise/search_scope.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #execute ⇒ Object
- #filter(filters = {}) ⇒ Object
-
#initialize(scope, options = {}) ⇒ SearchScope
constructor
A new instance of SearchScope.
- #order(order) ⇒ Object
- #page(number) ⇒ Object
- #query(terms = nil) ⇒ Object
- #to_attributes ⇒ Object
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, = {}) @scope = scope.to_s @filters = .delete(:filters) { Hash.new } @order = .delete(:order) @page = .delete(:page) @query = .delete(:query) end |
Instance Attribute Details
#scope ⇒ Object (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
#execute ⇒ Object
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_attributes ⇒ Object
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 |