Class: DNZ::CustomSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/dnz/custom_search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes = {}) ⇒ CustomSearch

Returns a new instance of CustomSearch.



19
20
21
22
# File 'lib/dnz/custom_search.rb', line 19

def initialize(client, attributes = {})
  @client = client
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/dnz/custom_search.rb', line 32

def method_missing(method, *args, &block)
  if @attributes.has_key?(method.to_sym)
    @attributes[method.to_sym]
  else
    super
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/dnz/custom_search.rb', line 17

def attributes
  @attributes
end

Instance Method Details

#[](key) ⇒ Object



24
25
26
# File 'lib/dnz/custom_search.rb', line 24

def [](key)
  @attributes[key]
end

#[]=(key, value) ⇒ Object



28
29
30
# File 'lib/dnz/custom_search.rb', line 28

def []=(key, value)
  @attributes[key] = value
end

#previewObject



40
41
42
43
44
45
46
47
48
# File 'lib/dnz/custom_search.rb', line 40

def preview
  options = {:validate => false, :search_text => '*:*'}
  attributes.each do |key, value|
    options['custom_search[%s]' % key] = value
  end
  
  xml = @client.fetch(:custom_search_preview, options)
  DNZ::Results.new(xml, self)
end

#textObject



50
51
52
# File 'lib/dnz/custom_search.rb', line 50

def text
  attributes[:search_term] || ''
end