Class: SecQuery::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/sec_query/transaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ Transaction

Returns a new instance of Transaction.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sec_query/transaction.rb', line 6

def initialize(transaction)
    @filing_number = transaction[:form].split("/")[-2][0..19]
    @code = transaction[:code]
    if transaction[:date] != nil and transaction[:date] != "-"
        date = transaction[:date].split("-")
        @date = Time.utc(date[0],date[1],date[2])
    end
    @reporting_owner = transaction[:reporting_owner]
    @form = transaction[:form]
    @type = transaction[:type]
    @modes = transaction[:modes]
    @shares = transaction[:shares].to_f
    @price = transaction[:price].gsub("$", "").to_f
    @owned = transaction[:owned].to_f
    @number = transaction[:number].to_i
    @owner_cik = transaction[:owner_cik]
    @security_name = transaction[:security_name]
    @deemed = transaction[:deemed]
    @exercise = transaction[:exercise]
    @nature = transaction[:nature]
    @derivative = transaction[:derivative]
    @underlying_1 = transaction[:underlying_1].to_f
    @exercised = transaction[:exercised]
    @underlying_2 = transaction[:underlying_2].to_f
    if transaction[:expires] != nil;
        expires = transaction[:expires].split("-")
        @expires = Time.utc(expires[0],expires[1],expires[2].to_i)
    end
    @underlying_3 = transaction[:underlying_3].to_f
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def code
  @code
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def date
  @date
end

#deemedObject

Returns the value of attribute deemed.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def deemed
  @deemed
end

#derivativeObject

Returns the value of attribute derivative.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def derivative
  @derivative
end

#exerciseObject

Returns the value of attribute exercise.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def exercise
  @exercise
end

#exercisedObject

Returns the value of attribute exercised.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def exercised
  @exercised
end

#expiresObject

Returns the value of attribute expires.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def expires
  @expires
end

#filing_numberObject

Returns the value of attribute filing_number.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def filing_number
  @filing_number
end

#formObject

Returns the value of attribute form.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def form
  @form
end

#modesObject

Returns the value of attribute modes.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def modes
  @modes
end

#natureObject

Returns the value of attribute nature.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def nature
  @nature
end

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def number
  @number
end

#ownedObject

Returns the value of attribute owned.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def owned
  @owned
end

#owner_cikObject

Returns the value of attribute owner_cik.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def owner_cik
  @owner_cik
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def price
  @price
end

#reporting_ownerObject

Returns the value of attribute reporting_owner.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def reporting_owner
  @reporting_owner
end

#security_nameObject

Returns the value of attribute security_name.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def security_name
  @security_name
end

#sharesObject

Returns the value of attribute shares.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def shares
  @shares
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def type
  @type
end

#underlying_1Object

Returns the value of attribute underlying_1.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def underlying_1
  @underlying_1
end

#underlying_2Object

Returns the value of attribute underlying_2.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def underlying_2
  @underlying_2
end

#underlying_3Object

Returns the value of attribute underlying_3.



4
5
6
# File 'lib/sec_query/transaction.rb', line 4

def underlying_3
  @underlying_3
end

Class Method Details

.find(entity, start, count, limit) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
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
# File 'lib/sec_query/transaction.rb', line 37

def self.find(entity, start, count, limit)

    if start == nil; start = 0; end
    if count == nil; count = 80; end
    url = "http://www.sec.gov/cgi-bin/own-disp?action=get"+entity[:type]+"&CIK="+entity[:cik]+"&start="+start.to_s+"&count="+count.to_s
    response = Entity.query(url)
    doc = Hpricot(response)
    trans = doc.search("//td[@width='40%']")[0].parent.parent.search("//tr")
    i= start;
    query_more = false;
    for tran in trans
        td = tran.search("//td")
        if td[2] != nil and td[1].innerHTML != "Exercise"
                query_more = true;
                if !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;
                if trans[i+1]; n_td = trans[i+1].search("//td"); end
                if n_td != nil and n_td.count ==7 and 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=i+1 
    end
    if query_more and limit == nil || query_more and !limit
        Transaction.find(entity, start+count, count, limit);
    else
        return entity
    end
end