Class: WhosGotDirt::Responses::Entity::Poderopedia

Inherits:
WhosGotDirt::Response show all
Defined in:
lib/whos_got_dirt/responses/entity/poderopedia.rb

Overview

Converts entities from the Poderopedia API to Popolo format.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from WhosGotDirt::Response

Instance Method Details

#countFixnum

Returns the total number of matching results.

Returns:

  • (Fixnum)

    the total number of matching results



29
30
31
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 29

def count
  parsed_body.size
end

#item_url(result) ⇒ String

Returns an entity's URL.

Parameters:

  • result (Hash)

    the rendered result

Returns:

  • (String)

    the entity's URL



46
47
48
49
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 46

def item_url(result)
  query = CGI.parse(env.url.query.to_s)
  "#{env.url.scheme}://#{env.url.host}/visualizacion/getEntityById?id=#{CGI.escape(result['identifiers'][0]['identifier'].to_s)}&entity=#{CGI.escape(query['entity'][0].to_s)}&user_key=#{CGI.escape(query['user_key'][0].to_s)}"
end

#parse_bodyArray<Hash>

Parses the response body.

Returns:

  • (Array<Hash>)

    the parsed response body



21
22
23
24
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 21

def parse_body
  parsed = JSON.load(body)
  parsed['organization'] || parsed['person']
end

#to_aArray<Hash>

Transforms the parsed response body into results.

Returns:

  • (Array<Hash>)

    the results



36
37
38
39
40
# File 'lib/whos_got_dirt/responses/entity/poderopedia.rb', line 36

def to_a
  parsed_body.map do |data|
    Result.new('Entity', renderer.result(data), self).finalize!
  end
end