Class: BlizzardApi::Wow::SearchComposer
- Inherits:
 - 
      Object
      
        
- Object
 - BlizzardApi::Wow::SearchComposer
 
 
- Defined in:
 - lib/blizzard_api/wow/search/search_composer.rb
 
Overview
Composer for search endpoint arguments
Instance Attribute Summary collapse
- 
  
    
      #fields  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute fields.
 - 
  
    
      #order  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute order.
 - 
  
    
      #page  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute page.
 - 
  
    
      #page_size  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute page_size.
 
Instance Method Summary collapse
- 
  
    
      #initialize(page, page_size)  ⇒ SearchComposer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of SearchComposer.
 - 
  
    
      #order_by(field, mode = :asc)  ⇒ SearchComposer 
    
    
  
  
  
  
  
  
  
  
  
    
Add a sort field.
 - 
  
    
      #to_search_query  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a valid queryString based on the options.
 - 
  
    
      #where(field, value)  ⇒ SearchComposer 
    
    
  
  
  
  
  
  
  
  
  
    
Add a search field.
 - 
  
    
      #where_not(field, value)  ⇒ SearchComposer 
    
    
  
  
  
  
  
  
  
  
  
    
Add a search field.
 
Constructor Details
#initialize(page, page_size) ⇒ SearchComposer
Returns a new instance of SearchComposer.
      10 11 12 13 14 15  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 10 def initialize(page, page_size) self.page = page self.page_size = page_size self.fields = [] self.order = [] end  | 
  
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
      8 9 10  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 8 def fields @fields end  | 
  
#order ⇒ Object
Returns the value of attribute order.
      8 9 10  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 8 def order @order end  | 
  
#page ⇒ Object
Returns the value of attribute page.
      8 9 10  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 8 def page @page end  | 
  
#page_size ⇒ Object
Returns the value of attribute page_size.
      8 9 10  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 8 def page_size @page_size end  | 
  
Instance Method Details
#order_by(field, mode = :asc) ⇒ SearchComposer
Add a sort field
      58 59 60 61 62 63  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 58 def order_by(field, mode = :asc) raise ArgumentError, 'Invalid order mode.' unless %i[asc desc].include? mode order.push "#{field}:#{mode}" self end  | 
  
#to_search_query ⇒ String
Returns a valid queryString based on the options
      69 70 71 72 73 74  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 69 def to_search_query query_string = "_page=#{page}&_pageSize=#{page_size}" query_string += "&#{fields.join('&')}" unless fields.size.zero? query_string += "&orderby=#{order.join(',')}" unless order.size.zero? query_string end  | 
  
#where(field, value) ⇒ SearchComposer
Add a search field
The second argument takes a simple value, an array of values or a hash for range searches.
      29 30 31 32  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 29 def where(field, value) fields.push "#{field}=#{URI.encode_www_form_component(resolve_value(value))}" self end  | 
  
#where_not(field, value) ⇒ SearchComposer
Add a search field
The second argument takes a simple value, an array of values or a hash for range searches.
      46 47 48 49  | 
    
      # File 'lib/blizzard_api/wow/search/search_composer.rb', line 46 def where_not(field, value) fields.push "#{field}!=#{URI.encode_www_form_component(resolve_value(value))}" self end  |