Class: SecQuery::Entity

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

Overview

> SecQuery::Entity

SecQuery::Entity is the root class which is responsible for requesting, parsing and initializing SecQuery::Entity intances from SEC Edgar.

Constant Summary collapse

COLUMNS =
[:cik, :name, :mailing_address, :business_address,
:assigned_sic, :assigned_sic_desc, :assigned_sic_href, :assitant_director, :cik_href,
:formerly_names, :state_location, :state_location_href, :state_of_incorporation]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ Entity

Returns a new instance of Entity.



12
13
14
15
16
# File 'lib/sec_query/entity.rb', line 12

def initialize(entity)
  COLUMNS.each do |column|
    instance_variable_set("@#{ column }", entity[column.to_s])
  end
end

Class Method Details

.find(entity_args) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/sec_query/entity.rb', line 33

def self.find(entity_args)
  temp = {}
  temp[:url] = SecURI.browse_edgar_uri(entity_args)
  temp[:url][:action] = :getcompany
  response = query(temp[:url].output_atom.to_s)
  document = Nokogiri::HTML(response)
  xml = document.xpath("//feed/company-info")
  Entity.new(parse(xml))
end

.parse(xml) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sec_query/entity.rb', line 43

def self.parse(xml)
  content = Hash.from_xml(xml.to_s)
  if content['company_info'].present?
    content = content['company_info']
    content['name'] = content.delete('conformed_name')
    if content['formerly_names'].present?
      content['formerly_names'] = content.delete('formerly_names')['names']
    end
    content['addresses']['address'].each do |address|
      content["#{address['type']}_address"] = address unless address.nil?
    end
    return content
  else
    return {}
  end
end

.query(url) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/sec_query/entity.rb', line 22

def self.query(url)
  RestClient.get(url) do |response, request, result, &block|
    case response.code
    when 200
      return response
    else
      response.return!(request, result, &block)
    end
  end
end

Instance Method Details

#filings(args = {}) ⇒ Object



18
19
20
# File 'lib/sec_query/entity.rb', line 18

def filings(args={})
  Filing.find(@cik, 0, 80, args)
end