Sha256: 55483f9127243bea801c8d589dac73560f6e545336572af9fdfa6e14b664241f

Contents?: true

Size: 774 Bytes

Versions: 11

Compression:

Stored size: 774 Bytes

Contents

module NNEClient
  # @!visibility private
  class Query
    def initialize(query_hash, xml)
      @query_hash = query_hash
      @xml = xml
    end

    def render
      Question.new(@query_hash, @xml).render
      tag(:int_2, hits_per_page, :int)
      tag(:int_3, wanted_page_number, :int)
      tag(:int_4, include_ad_protected, :int)
      tag(:String_5, NNEClient.config.access_key, :string)
    end

    private

    def include_ad_protected
      @query_hash[:include_ad_protected] ? 1 : 0
    end

    def hits_per_page
      @query_hash[:hits_per_page] || 10
    end

    def wanted_page_number
      @query_hash[:wanted_page_number] || 1
    end

    def tag(attribute, value, type)
      @xml.tag!(attribute, value, 'xsi:type' => "xsd:#{type}")
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
nne_client-0.0.11 lib/nne_client/query.rb
nne_client-0.0.10 lib/nne_client/query.rb
nne_client-0.0.9 lib/nne_client/query.rb
nne_client-0.0.8 lib/nne_client/query.rb
nne_client-0.0.7 lib/nne_client/query.rb
nne_client-0.0.6 lib/nne_client/query.rb
nne_client-0.0.5 lib/nne_client/query.rb
nne_client-0.0.4 lib/nne_client/query.rb
nne_client-0.0.3 lib/nne_client/query.rb
nne_client-0.0.2 lib/nne_client/query.rb
nne_client-0.0.1 lib/nne_client/query.rb