class ThirteenF::CusipSecurities
Constants
- BASE_URL
Attributes
file_location[R]
file_name[R]
list_entries[R]
period_end[R]
quarter[R]
Public Class Methods
all_file_locations()
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 12 def self.all_file_locations index_url = "#{BASE_URL}/divisions/investment/13flists.htm" page = SecRequest.get index_url, response_type: :html a_tags = page.search('a').select do |a_tag| href = a_tag.attributes['href']&.value.to_s href.include?('13flist') && href.include?('.pdf') end a_tags.map { |a_tag|"#{BASE_URL + a_tag.attributes['href'].value}" } end
most_recent_list()
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 22 def self.most_recent_list index_url = "#{BASE_URL}/divisions/investment/13flists.htm" page = SecRequest.get index_url, response_type: :html a_tag = page.search('a').find { |a| a.text.include?('Current List') } file_location = "#{BASE_URL + a_tag.attributes['href'].value}" new file_location end
new(file_location)
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 30 def initialize(file_location) @file_location = file_location @file_name = file_location.split('/').last @quarter = set_quarter_string file_name @period_end = set_period_end file_name true end
Public Instance Methods
get_list_entries()
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 38 def get_list_entries return false unless file_location io = URI.open file_location reader = PDF::Reader.new io valid_entries = [] reader.pages[2..-1].each do |page| lines = page.text.split("\n").reject(&:empty?)[3..-1] line_arrs = lines.map do |line| next nil if line.include?('Total Coun') line.split(/\s{3}|( \* )/).reject(&:empty?).map(&:strip).reject { |text| text == '*' } end line_arrs.compact.each do |line_arr| next unless line_arr.count > 1 valid_entries.push ListEntry.new(line_arr) end end @list_entries = valid_entries true end
Private Instance Methods
set_period_end(file_name)
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 81 def set_period_end(file_name) arr = file_name.sub('13flist', '').delete('.pdf').split('q') case arr[1].to_i when 1 then Date.parse("#{arr[0]}-03-31") when 2 then Date.parse("#{arr[0]}-06-30") when 3 then Date.parse("#{arr[0]}-09-30") when 4 then Date.parse("#{arr[0]}-12-31") end end
set_quarter_string(file_name)
click to toggle source
# File lib/thirteen_f/cusip_securities.rb, line 71 def set_quarter_string(file_name) arr = file_name.sub('13flist', '').delete('.pdf').split('q') case arr[1].to_i when 1 then "1st Quarter #{arr[0]}" when 2 then "2nd Quarter #{arr[0]}" when 3 then "3rd Quarter #{arr[0]}" when 4 then "4th Quarter #{arr[0]}" end end