class Sec::Firms::FirmParser
Constants
- SEC_FIRM_DETAIL_FILE_NAME
- SEC_FIRM_URL
Public Class Methods
new(cik_id)
click to toggle source
Calls superclass method
# File lib/sec/firms/firm_parser.rb, line 7 def initialize(cik_id) fetch_url = SEC_FIRM_URL.gsub(':CIK_ID', cik_id) xml_str = Net::HTTP.get(URI.parse(fetch_url)) super(xml_str) end
Public Instance Methods
entries()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 39 def entries doc.xpath('//xmlns:entry').map do |entry| filing_date = Date.parse(entry.at('filing-date').text) accession_number = entry.at('accession-nunber').text [ [filing_date, accession_number], entry ] end.sort_by { |value| value[0] } end
id()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 13 def id doc.xpath('//xmlns:cik').text end
name()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 21 def name default_values doc.xpath('//xmlns:conformed-name').text end
slug()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 17 def slug Slugify.convert(name[:value], true) end
to_hash()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 25 def to_hash data = Hash.from_xml(doc.to_s).try(:[], 'feed').try(:[], 'company_info') || [] data = Helpers::transform_hash(data) do |hash, key, value| hash[key.underscore] = default_values(value) end { id: id, slug: slug, name: name }.merge(data).merge(entries_attributes) .deep_transform_keys { |key| key.to_s.underscore } end
Private Instance Methods
default_values(value)
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 56 def default_values(value) { value: value, updated_at: updated_at } end
entries_attributes()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 63 def entries_attributes hash = {} details = entries.map do |entry| FirmEntryParser.new( Downloader.new(entry_url(entry[1])).content, entry[0][0] ).to_hash end details.each do |detail| hash.merge!(detail) end hash end
entry_url(entry)
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 77 def entry_url(entry) url = entry.at('filing-href').text url.gsub(url.split('/')[-1], SEC_FIRM_DETAIL_FILE_NAME) end
updated_at()
click to toggle source
# File lib/sec/firms/firm_parser.rb, line 52 def updated_at @updated_at ||= doc.xpath('//xmlns:feed').at('updated').text end