Class: BlizzardApi::Wow::SearchComposer

Inherits:
Object
  • Object
show all
Defined in:
lib/blizzard_api/wow/search/search_composer.rb

Overview

Composer for search endpoint arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fieldsObject

Returns the value of attribute fields.



8
9
10
# File 'lib/blizzard_api/wow/search/search_composer.rb', line 8

def fields
  @fields
end

#orderObject

Returns the value of attribute order.



8
9
10
# File 'lib/blizzard_api/wow/search/search_composer.rb', line 8

def order
  @order
end

#pageObject

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_sizeObject

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

Parameters:

  • field (String)

    Field name

  • mode (Symbol) (defaults to: :asc)

    :asc or :desc

Returns:

Raises:

  • (ArgumentError)


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_queryString

Returns a valid queryString based on the options

Returns:

  • (String)


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.

Parameters:

  • field (String)

    Field name

  • value (String|Integer|Hash|Array<Integer>|Array<String>)

Options Hash (value):

  • :min (Integer)

    Range start

  • :max (Integer)

    Range end

  • :mode (Integer)

    Range mode (:inclusive|:exclusive)

Returns:



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.

Parameters:

  • field (String)

    Field name

  • value (String|Integer|Hash|Array<Integer>|Array<String>)

Options Hash (value):

  • :min (Integer)

    Range start

  • :max (Integer)

    Range end

  • :mode (Integer)

    Range mode (:inclusive|:exclusive)

Returns:



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