Class: SecEdgar::FilingUpdater

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ FilingUpdater

Returns a new instance of FilingUpdater.



5
6
7
# File 'lib/sec_edgar/filing_updater.rb', line 5

def initialize(form)
  @form = form
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



3
4
5
# File 'lib/sec_edgar/filing_updater.rb', line 3

def form
  @form
end

Instance Method Details

#docObject



9
10
11
# File 'lib/sec_edgar/filing_updater.rb', line 9

def doc
  @doc ||= RawFiling.for_form(form).parsed
end

#updateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sec_edgar/filing_updater.rb', line 13

def update
  doc_json = doc.to_json
  return if doc_json == '{}'

  form.update({
    dollar_volume: doc.dollar_volume,
    document: { d: doc_json }
  })

  unless form.company
    form.company = Company.where(cik: doc.issuer_cik).first_or_initialize
    form.company.update_attributes(
      name: doc.issuer_name,
      ticker: doc.issuer_trading_symbol.upcase
    )
  end

  unless form.insider
    form.insider = Insider.where(cik: doc.owner_cik).first_or_initialize
    form.insider.update_attributes(
      name: doc.owner_name[0, 254]
    )
  end

  dt = Date.parse(form.date)
  form.day_traded_price = form.company.price_on(dt)
  form.day_traded_volume = form.company.volume_on(dt)
  form.plus_3_months_price = form.company.price_on(dt + 3.months)
  form.plus_6_months_price = form.company.price_on(dt + 6.months)
  form.plus_12_months_price = form.company.price_on(dt + 12.months)
  # need to find a more detailed data source
  # form.price_to_earnings = Company.price_to_earnings_on(form.date)
  # form.price_to_book = Company.price_to_book_on(form.date)

  form.doc = doc
  form.save!
  form
end