Class: SecEdgar::Poll

Inherits:
Object
  • Object
show all
Defined in:
lib/sec_edgar/poll.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = 1993, qtr = 1, client = SecEdgar::FtpClient.instance, local_base = "./assets") ⇒ Poll

Returns a new instance of Poll.



37
38
39
40
41
42
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



35
36
37
# File 'lib/sec_edgar/poll.rb', line 35

def client
  @client
end

#local_baseObject (readonly)

Returns the value of attribute local_base.



35
36
37
# File 'lib/sec_edgar/poll.rb', line 35

def local_base
  @local_base
end

#quarterObject (readonly)

Returns the value of attribute quarter.



35
36
37
# File 'lib/sec_edgar/poll.rb', line 35

def quarter
  @quarter
end

#yearObject (readonly)

Returns the value of attribute year.



35
36
37
# File 'lib/sec_edgar/poll.rb', line 35

def year
  @year
end

Class Method Details

.all(from_year, to_year, &blk) ⇒ Object



44
45
46
47
48
49
50
# 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

.polls_by_year(from_year, to_year) ⇒ Object



52
53
54
55
56
57
58
59
60
# 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

Instance Method Details

#filingsObject



87
88
89
90
91
# File 'lib/sec_edgar/poll.rb', line 87

def filings
  index.scrub.split("\n").select do |line|
    line =~ filing_regexp
  end
end

#form4sObject



74
75
76
77
78
79
80
81
82
83
84
85
# 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

#indexObject



66
67
68
69
70
71
72
# 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_fileObject



93
94
95
# File 'lib/sec_edgar/poll.rb', line 93

def local_file
  "#{ local_dir }/master.idx"
end

#to_sObject



62
63
64
# File 'lib/sec_edgar/poll.rb', line 62

def to_s
  "<Poll y: #{ year } q: #{ quarter }>"
end