Class: SecQuery::Filing
- Inherits:
-
Object
- Object
- SecQuery::Filing
- Defined in:
- lib/sec_query/filing.rb
Overview
> SecQuery::Filing
SecQuery::Filing requests and parses filings for any given SecQuery::Entity
Constant Summary collapse
- COLUMNS =
[:cik, :title, :summary, :link, :term, :date, :file_id]
Class Method Summary collapse
- .fetch(uri, &blk) ⇒ Object
- .find(cik, start = 0, count = 80) ⇒ Object
- .for_cik(cik, options = {}, &blk) ⇒ Object
- .parse(cik, document) ⇒ Object
- .parse_rss(rss, &blk) ⇒ Object
- .recent(options = {}, &blk) ⇒ Object
- .uri_for_cik(cik, start = 0, count = 100) ⇒ Object
- .uri_for_recent(start = 0, count = 100) ⇒ Object
Instance Method Summary collapse
-
#initialize(filing) ⇒ Filing
constructor
A new instance of Filing.
Constructor Details
#initialize(filing) ⇒ Filing
Returns a new instance of Filing.
11 12 13 14 15 |
# File 'lib/sec_query/filing.rb', line 11 def initialize(filing) COLUMNS.each do |column| instance_variable_set("@#{ column }", filing[column]) end end |
Class Method Details
.fetch(uri, &blk) ⇒ Object
17 18 19 20 21 |
# File 'lib/sec_query/filing.rb', line 17 def self.fetch(uri, &blk) open(uri) do |rss| parse_rss(rss, &blk) end end |
.find(cik, start = 0, count = 80) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sec_query/filing.rb', line 85 def self.find(cik, start = 0, count = 80) temp = {} temp[:url] = SecURI.browse_edgar_uri({cik: cik}) temp[:url][:action] = :getcompany temp[:url][:start] = start temp[:url][:count] = count response = Entity.query(temp[:url].output_atom.to_s) document = Nokogiri::HTML(response) parse(cik, document) end |
.for_cik(cik, options = {}, &blk) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sec_query/filing.rb', line 36 def self.for_cik(cik, = {}, &blk) start = .fetch(:start, 0) count = .fetch(:count, 100) limit = .fetch(:limit, 100) fetch(uri_for_cik(cik, start, count), &blk) start += count return if start >= limit for_cik(cik, { start: start, count: count, limit: limit }, &blk) rescue OpenURI::HTTPError return end |
.parse(cik, document) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sec_query/filing.rb', line 96 def self.parse(cik, document) filings = [] if document.xpath('//content').to_s.length > 0 document.xpath('//content').each do |e| if e.xpath('//content/accession-nunber').to_s.length > 0 content = Hash.from_xml(e.to_s)['content'] content[:cik] = cik content[:file_id] = content.delete('accession_nunber') content[:date] = content.delete('filing_date') content[:link] = content.delete('filing_href') content[:term] = content.delete('filing_type') content[:title] = content.delete('form_name') filings << Filing.new(content) end end end filings end |
.parse_rss(rss, &blk) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sec_query/filing.rb', line 69 def self.parse_rss(rss, &blk) feed = RSS::Parser.parse(rss, false) feed.entries.each do |entry| filing = Filing.new({ cik: entry.title.content.match(/\((\w{10})\)/)[1], file_id: entry.id.content.split('=').last, term: entry.category.term, title: entry.title.content, summary: entry.summary.content, date: DateTime.parse(entry.updated.content.to_s), link: entry.link.href.gsub('-index.htm', '.txt') }) blk.call(filing) end end |
.recent(options = {}, &blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sec_query/filing.rb', line 23 def self.recent( = {}, &blk) start = .fetch(:start, 0) count = .fetch(:count, 100) limit = .fetch(:limit, 100) limited_count = [limit - start, count].min fetch(uri_for_recent(start, limited_count), &blk) start += count return if start >= limit recent({ start: start, count: count, limit: limit }, &blk) rescue OpenURI::HTTPError return end |
.uri_for_cik(cik, start = 0, count = 100) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sec_query/filing.rb', line 58 def self.uri_for_cik(cik, start = 0, count = 100) SecURI.browse_edgar_uri( action: :getcompany, owner: :include, output: :atom, start: start, count: count, CIK: cik ) end |
.uri_for_recent(start = 0, count = 100) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/sec_query/filing.rb', line 48 def self.uri_for_recent(start = 0, count = 100) SecURI.browse_edgar_uri( action: :getcurrent, owner: :include, output: :atom, start: start, count: count ) end |