class BlizzardApi::Wow::SearchComposer
Composer for search endpoint arguments
Attributes
Public Class Methods
# 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
Public Instance Methods
Add a sort field
@param field [String] Field name @param mode [Symbol] :asc or :desc
@return {SearchComposer}
# 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
Returns a valid queryString based on the options
@return {String}
# 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
Add a search field
The second argument takes a simple value, an array of values or a hash for range searches.
@param field [String] Field name @param value [String|Integer|Hash|Array<Integer>|Array<String>] @option value [Integer] :min Range start @option value [Integer] :max Range end @option value [Integer] :mode Range mode (:inclusive|:exclusive)
@return {SearchComposer}
# 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
Add a search field
The second argument takes a simple value, an array of values or a hash for range searches.
@param field [String] Field name @param value [String|Integer|Hash|Array<Integer>|Array<String>] @option value [Integer] :min Range start @option value [Integer] :max Range end @option value [Integer] :mode Range mode (:inclusive|:exclusive)
@return {SearchComposer}
# 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
Protected Instance Methods
# File lib/blizzard_api/wow/search/search_composer.rb, line 86 def resolve_hash(value) min = value.key?(:min) ? value[:min] : '' max = value.key?(:max) ? value[:max] : '' mode = value.key?(:mode) ? value[:mode] : :inclusive return "[#{min},#{max}]" if mode.eql? :inclusive "(#{min},#{max})" end
# File lib/blizzard_api/wow/search/search_composer.rb, line 78 def resolve_value(value) return value.join '||' if value.is_a? Array return value.to_s unless value.is_a? Hash resolve_hash value end