Class: Resumr

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

Class Method Summary collapse

Class Method Details

.new(file) ⇒ Object



4
5
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
36
37
38
39
# File 'lib/resumr.rb', line 4

def self.new(file)
    reader = PDF::Reader.new(file)
    info = reader.info
    pages = reader.pages

    text = pages.map{|x| x.text}.reduce{|x,y| x << y}.gsub(/Page \w of \w/,"")
    right, left = "", ""

    text.each_line do |line|
        if line.length <= 40 || line.include?("Top Skills") || line.include?("Contact")
            left += line.strip + "\n"
        else
            left += line.slice(0,40).strip + "\n"
            right += line.slice(40,line.length).strip + "\n"
        end
    end

    linkedin_url_start_index = left.index("www.linkedin.com")
    linkedin_url_end_index = left.index("(LinkedIn)")
    
    resume =  {
        source: info[:Author],
        time: Time.new(info[:CreationDate].gsub(/D:/,"")),
        text: text,
        left: left,
        right: right,
        pdf_reader: reader,
        sections: subsection_title_list(left).merge!(subsection_title_list(right,true)),
        linkedin_url: left[linkedin_url_start_index..linkedin_url_end_index-1].gsub("\n","").strip
    }

    name = resume[:sections][:beginning].lines[1].split("\n").first
    resume.merge!({name: name})

    return resume
end

.subsection_title_list(str, with_first_block_sepparate = false) ⇒ Object



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
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/resumr.rb', line 41

def self.subsection_title_list(str, with_first_block_sepparate = false)
    possible_titles = [
        ["Top Skills", "Principais competências"],
        ["Certifications"], 
        ["Contact", "Contato", "Contatar"],
        ["Experience","Experiência"],
        ["Education", "Formação Acadêmica"],
        ["Summary","Resumo"],
        ["Languages"],
        ["Publications"]
    ]
    indexes = {}
    possible_titles.each do |tit|
        new_keyvalue = {}
        title = tit[0]
        index = nil
        tit.each do |synonym|
            index = str.index(synonym) if index.nil?
        end
        if ! index.nil?
            new_keyvalue.store(
                index,
                title.gsub(" ","_").downcase.to_sym
            )
            indexes.merge!(new_keyvalue)
        end
    end
    
    retorn = {}
    sorted_indexes = indexes.keys.sort

    if with_first_block_sepparate
        first_block_index = sorted_indexes[0]

        retorn.merge!(
            {beginning: 
                str[0..(first_block_index-1)]
            }
        )

    end

    sorted_indexes.each.with_index do |current_block_index, k|
        new_keyvalue = {}
        next_block_index = 0
        if k == (sorted_indexes.length - 1)
            next_block_index = str.length
        else
            next_block_index = sorted_indexes[k+1]
        end
        new_keyvalue.store(
            indexes[current_block_index],
            str[current_block_index..next_block_index].lines[1..-1].join
        )
        retorn.merge!(new_keyvalue)
    end 

    return retorn
end