Class: Wreckster::Traversal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, name) ⇒ Traversal

Returns a new instance of Traversal.



7
8
9
10
# File 'lib/wreckster/traversal.rb', line 7

def initialize base, name
  @base = base
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/wreckster/traversal.rb', line 5

def name
  @name
end

Instance Method Details

#find(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/wreckster/traversal.rb', line 12

def find options = {}
  params = options.map { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join("&")
  map = JSON.parse(
    Wreckster.connection.request(URI.parse(url + "?#{params}")).body
  )
  return map['score'] if map.key?('score')

  map['ranks'].map { |thing| Wreckster::Object.new(name, thing) }
end

#infoObject



22
23
24
# File 'lib/wreckster/traversal.rb', line 22

def info
  JSON.parse Net::HTTP.get(URI.parse(url))
end

#urlObject



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

def url
  @base + @name
end