Class: NDLSearch::NDLSearch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNDLSearch

Returns a new instance of NDLSearch.



12
13
14
# File 'lib/ndl_search.rb', line 12

def initialize
  @feed = nil
end

Instance Attribute Details

#feedObject

Returns the value of attribute feed.



10
11
12
# File 'lib/ndl_search.rb', line 10

def feed
  @feed
end

Instance Method Details

#construct_query(query) ⇒ Object



21
22
23
24
# File 'lib/ndl_search.rb', line 21

def construct_query(query)
  url = API_PATH+"?"+create_params(query)
  URI.escape(url)
end

#create_params(hash) ⇒ Object



26
27
28
# File 'lib/ndl_search.rb', line 26

def create_params(hash)
  hash.to_a.map{|item| "#{item[0]}=#{item[1]}"}.join("&")
end

#search(query) ⇒ Object



16
17
18
19
# File 'lib/ndl_search.rb', line 16

def search(query)
  source = RestClient.get(construct_query(query))
  ::NDLSearch::SearchResult.new(::REXML::Document.new(source))
end