Class: WhosGotDirt::Responses::Entity::CorpWatch

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

Overview

Converts entities from the CorpWatch 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



50
51
52
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 50

def count
  Integer(parsed_body['meta']['total_results'])
end

#indexFixnum

Returns the current index.

Returns:

  • (Fixnum)

    the current index



57
58
59
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 57

def index
  parsed_body['meta']['parameters']['index']
end

#item_url(result) ⇒ String

Returns an entity's URL.

Parameters:

  • result (Hash)

    the rendered result

Returns:

  • (String)

    the entity's URL



78
79
80
81
82
83
84
85
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 78

def item_url(result)
  query = CGI.parse(env.url.query.to_s)
  url = "#{env.url.scheme}://#{env.url.host}#{env.url.path.sub(/\.json\z/, '')}/#{result['identifiers'][0]['identifier']}.json"
  if query['key'].any?
    url += "?key=#{CGI.escape(query['key'][0].to_s)}"
  end
  url
end

#parse_bodyArray<Hash>

Parses the response body.

Returns:

  • (Array<Hash>)

    the parsed response body



43
44
45
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 43

def parse_body
  JSON.load(body)
end

#to_aArray<Hash>

Transforms the parsed response body into results.

Returns:

  • (Array<Hash>)

    the results



64
65
66
67
68
69
70
71
72
# File 'lib/whos_got_dirt/responses/entity/corp_watch.rb', line 64

def to_a
  if parsed_body['result']['companies']
    parsed_body['result']['companies'].map do |_,data|
      Result.new('Entity', renderer.result(data), self).finalize!
    end
  else
    []
  end
end