Class: SitelinkGenerator::SecEdgar

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sitelink_generator/generators/sec_edgar.rb

Constant Summary collapse

MATCHING_URL_REGEX =
%r{^(?!.*-index\.htm$)https?://(www\.)?sec\.gov/Archives/edgar/data/\d+/\d+\/.+$}i
DEFAULT_BROWSE_EDGAR_PARAMS =
{
  Find: 'Search',
  action: 'getcompany',
  owner: 'exclude'
}.freeze

Class Method Summary collapse

Class Method Details

.generate(url) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/sitelink_generator/generators/sec_edgar.rb', line 18

def self.generate(url)
  return [] unless url =~ MATCHING_URL_REGEX

  path_as_array = URI.parse(url).path.split('/')
  return [] unless path_as_array.length == 7

  [generate_full_filing_url(path_as_array),
   generate_browse_edgar_url(path_as_array)]
end

.generate_browse_edgar_url(path_as_array) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/sitelink_generator/generators/sec_edgar.rb', line 28

def self.generate_browse_edgar_url(path_as_array)
  title = I18n.t(:'sitelink_generator.sec_edgar.most_recent_filings')

  cik = path_as_array[4]
  url_params = DEFAULT_BROWSE_EDGAR_PARAMS.merge(CIK: cik)
  url = "http://www.sec.gov/cgi-bin/browse-edgar?#{url_params.to_param}"

  { title: title, url: url }
end

.generate_full_filing_url(path_as_array) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sitelink_generator/generators/sec_edgar.rb', line 38

def self.generate_full_filing_url(path_as_array)
  cik = path_as_array[4]
  cik_part_1 = path_as_array[5].slice(0, 10)
  cik_part_2 = path_as_array[5].slice(10, 2)
  cik_part_3 = path_as_array[5].slice(12..-1)

  full_filing_path = "#{cik}/#{cik_part_1}-#{cik_part_2}-#{cik_part_3}-index.htm"
  url = "http://www.sec.gov/Archives/edgar/data/#{full_filing_path}"

  { title: I18n.t('sitelink_generator.sec_edgar.full_filing'), url: url }
end