class SecEdgar::Poll

Attributes

client[R]
local_base[R]
quarter[R]
year[R]

Public Class Methods

all(from_year, to_year, &blk) click to toggle source
# File lib/sec_edgar/poll.rb, line 44
def self.all(from_year, to_year, &blk)
  polls_by_year(from_year, to_year).each do |poll|
    poll.form4s.each do |filing|
      blk.call(filing)
    end
  end
end
new(year = 1993, qtr = 1, client = SecEdgar::FtpClient.instance, local_base = "./assets") click to toggle source
# File lib/sec_edgar/poll.rb, line 37
def initialize(year = 1993, qtr = 1, client = SecEdgar::FtpClient.instance, local_base = "./assets")
  @client = client
  @year = year
  @quarter = qtr
  @local_base = local_base
end
polls_by_year(from_year, to_year) click to toggle source
# File lib/sec_edgar/poll.rb, line 52
def self.polls_by_year(from_year, to_year)
  polls = []
  (from_year..to_year).each do |yr|
    (1..4).each do |qtr|
      polls << self.new(yr, qtr)
    end
  end
  polls
end

Public Instance Methods

filings() click to toggle source
# File lib/sec_edgar/poll.rb, line 87
def filings
  index.scrub.split("\n").select do |line|
    line =~ filing_regexp
  end
end
form4s() click to toggle source
# File lib/sec_edgar/poll.rb, line 74
def form4s
  filings.select do |line|
    line =~ form4_regexp
  end.map do |f|
    begin
      PollFiling.new(*f.split("|"), client)
    rescue => e
      puts line
      raise e
    end
  end
end
index() click to toggle source
# File lib/sec_edgar/poll.rb, line 66
def index
  unless File.exist?(local_file)
    puts "fetching from sec #{ to_s }..."
    fetch
  end
  File.read(local_file)
end
local_file() click to toggle source
# File lib/sec_edgar/poll.rb, line 93
def local_file
  "#{ local_dir }/master.idx"
end
to_s() click to toggle source
# File lib/sec_edgar/poll.rb, line 62
def to_s
  "<Poll y: #{ year } q: #{ quarter }>"
end

Private Instance Methods

fetch() click to toggle source
# File lib/sec_edgar/poll.rb, line 117
def fetch
  client.fetch(remote, local_file)
rescue => e
  puts "SecEdgar::Poll#fetch_quarter failed for #{ year }, QTR#{ quarter }"
  puts "local: #{ local_file }"
  puts "remote: #{ remote }"
  puts e.message
ensure
  verify_download
end
filing_regexp() click to toggle source
# File lib/sec_edgar/poll.rb, line 103
def filing_regexp
  /^(\d+\|.*\|.*.txt)$/i
end
form4_regexp() click to toggle source
# File lib/sec_edgar/poll.rb, line 99
def form4_regexp
  /^(\d+\|.*\|4\|.*.txt)$/i
end
local_dir() click to toggle source
# File lib/sec_edgar/poll.rb, line 111
def local_dir
  path = "#{ local_base }/#{  year.to_s }/QTR#{ quarter }"
  FileUtils.mkdir_p(path)
  path
end
remote() click to toggle source
# File lib/sec_edgar/poll.rb, line 107
def remote
  "/edgar/full-index/#{ year }/QTR#{ quarter }/master.idx"
end
verify_download() click to toggle source
# File lib/sec_edgar/poll.rb, line 128
def verify_download
  File.delete(local_file) unless File.size?(local_file)
end