Class: SecQuery::Relationship

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relationship) ⇒ Relationship

Returns a new instance of Relationship.



7
8
9
10
11
12
13
# File 'lib/sec_query/relationship.rb', line 7

def initialize(relationship)
    @cik = relationship[:cik];
    @name = relationship[:name];
    @position = relationship[:position];
    date = relationship[:date].split("-")
    @date = Time.utc(date[0],date[1],date[2].to_i)
end

Instance Attribute Details

#cikObject

Relationships are Owner / Issuer Relationships between Entities, forged by Transactions.



6
7
8
# File 'lib/sec_query/relationship.rb', line 6

def cik
  @cik
end

#dateObject

Relationships are Owner / Issuer Relationships between Entities, forged by Transactions.



6
7
8
# File 'lib/sec_query/relationship.rb', line 6

def date
  @date
end

#nameObject

Relationships are Owner / Issuer Relationships between Entities, forged by Transactions.



6
7
8
# File 'lib/sec_query/relationship.rb', line 6

def name
  @name
end

#positionObject

Relationships are Owner / Issuer Relationships between Entities, forged by Transactions.



6
7
8
# File 'lib/sec_query/relationship.rb', line 6

def position
  @position
end

Class Method Details

.find(entity) ⇒ Object



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_query/relationship.rb', line 16

def self.find(entity)
    @relationships =[]

    if entity[:doc] != nil
        doc = entity[:doc]
    elsif entity[:cik] != nil
        doc = Entity.document(entity[:cik])[0]
    end
    
    type = "Ownership Reports for Issuers:"
    lines = doc.search("//table").search("//td").search("b[text()*='"+type+"']")
    if lines.empty?
        type = "Ownership Reports from:"
        lines = doc.search("//table").search("//td").search("b[text()*='"+type+"']");
    end
    if !lines.empty?
        relationship = {}
        lines= lines[0].parent.search("//table")[0].search("//tr")
        for line in lines
            link = line.search("//a")[0]
            if link.innerHTML != "Owner" and link.innerHTML != "Issuer"
                relationship[:name] = link.innerHTML;
                relationship[:cik] =  line.search("//td")[1].search("//a").innerHTML
                relationship[:date] = position = line.search("//td")[2].innerHTML
                relationship[:position] = line.search("//td")[3].innerHTML
                @relationship = Relationship.new(relationship)
                @relationships << @relationship
            
            end
        end
        return @relationships
    else
        return false
    end
end


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sec_query/relationship.rb', line 51

def self.print(relationships)
    if relationships
        puts "\n\t"+relationships[1]+"\n"
        printf("\t%-30s %-10s %-40s %-10s\n\n","Entity", "CIK", "Position", "Date")
        for relationship in issuer[:relationships]
            printf("\t%-30s %-10s %-40s %-10s\n",relationship.name, relationship.cik, relationship.position, relationship.date)
        end
    else
        puts "No relationships"
    end
end