Class: Wikidata::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wikidata/response.rb

Direct Known Subclasses

SearchResponse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/wikidata/response.rb', line 7

def initialize raw
  @raw = raw
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/wikidata/response.rb', line 16

def empty?
  @_empty ||= (
    @raw.body['entities'].nil? ||
    @raw.body['entities'].is_a?(Array) && @raw.body['entities'].empty? ||
    @raw.body['entities'].is_a?(String)
  )
end

#inspectObject



24
25
26
# File 'lib/wikidata/response.rb', line 24

def inspect
  "<#{self.class} results: #{results.inspect}>"
end

#resultsObject



11
12
13
14
# File 'lib/wikidata/response.rb', line 11

def results
  return [] if empty?
  @_results ||= raw_results.map{|r| Wikidata::Item.new(r) }
end