Class: SecQuery::Transaction
- Inherits:
-
Object
- Object
- SecQuery::Transaction
- Defined in:
- lib/sec_query/transaction.rb
Overview
> SecQuery::Transactions
SecQuery filings for any given SecQuery::Entity instance.
Constant Summary collapse
- STR_COLUMNS =
:code, :form, :type, :modes, :owner_cik, :security_name, :deemed, :exercise, :nature, :derivative, :exercised, :reporting_owner
- FLOAT_COLUMNS =
:shares, :owned, :underlying_1, :underlying_2, :underlying_3
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(transaction) ⇒ Transaction
constructor
A new instance of Transaction.
- #setup_columns(transaction) ⇒ Object
- #setup_date(transaction) ⇒ Object
- #setup_expires(transaction) ⇒ Object
Constructor Details
#initialize(transaction) ⇒ Transaction
Returns a new instance of Transaction.
17 18 19 20 21 22 23 24 |
# File 'lib/sec_query/transaction.rb', line 17 def initialize(transaction) @number = transaction[:number].to_i @price = transaction[:price].gsub('$', '').to_f @filing_number = transaction[:form].split('/')[-2][0..19] setup_columns(transaction) setup_date(transaction) setup_expires(transaction) end |
Class Method Details
.find(entity, start, count, limit) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sec_query/transaction.rb', line 49 def self.find(entity, start, count, limit) start ||= 0 count ||= 80 url = SecURI.ownership_display_uri({ action: "get#{entity[:type]}", CIK: entity[:cik], start: start, count: count }) response = Entity.query(url) doc = Hpricot(response) trans = doc.search("//td[@width='40%']")[0].parent.parent.search('//tr') i = start query_more = false trans.each do |tran| td = tran.search('//td') if td[2] && td[1].innerHTML != 'Exercise' query_more = true unless td[0].empty? transaction = {} transaction[:code] = td[0].innerHTML transaction[:date] = td[1].innerHTML transaction[:reporting_owner] = td[2].innerHTML transaction[:form] = td[3].innerHTML transaction[:type] = td[4].innerHTML transaction[:modes] = td[5].innerHTML transaction[:shares] = td[6].innerHTML transaction[:price] = td[7].innerHTML transaction[:owned] = td[8].innerHTML transaction[:number] = td[9].innerHTML transaction[:owner_cik] = td[10].innerHTML transaction[:security_name] = td[11].innerHTML transaction[:deemed] = td[12].innerHTML n_td = trans[i + 1].search('//td') if trans[i + 1] if n_td && n_td.count == 7 && n_td[0].innerHTML.empty? transaction[:exercise] = n_td[1].innerHTML transaction[:nature] = n_td[2].innerHTML transaction[:derivative] = n_td[3].innerHTML transaction[:underlying_1] = n_td[4].innerHTML transaction[:exercised] = n_td[5].innerHTML transaction[:underlying_2] = n_td[6].innerHTML transaction[:expires] = n_td[7].innerHTML transaction[:underlying_3] = n_td[8].innerHTML end entity[:transactions] << Transaction.new(transaction) end end i += 1 end if (query_more && limit.nil?) || (query_more && !limit) Transaction.find(entity, start + count, count, limit) else return entity end end |
Instance Method Details
#setup_columns(transaction) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/sec_query/transaction.rb', line 26 def setup_columns(transaction) STR_COLUMNS.each do |column| instance_variable_set("@#{ column }", transaction[column]) end FLOAT_COLUMNS.each do |column| instance_variable_set("@#{ column }", transaction[column].to_f) end end |
#setup_date(transaction) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/sec_query/transaction.rb', line 35 def setup_date(transaction) if transaction[:date] && transaction[:date] != '-' date = transaction[:date].split('-') @date = Time.utc(date[0], date[1], date[2]) end end |
#setup_expires(transaction) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/sec_query/transaction.rb', line 42 def setup_expires(transaction) if transaction[:expires] expires = transaction[:expires].split('-') @expires = Time.utc(expires[0], expires[1], expires[2].to_i) end end |