Class: LinkedinParser
- Inherits:
-
Object
- Object
- LinkedinParser
- Defined in:
- lib/linkedinparser.rb
Instance Method Summary collapse
-
#initialize(profile, profile_url, crawler_fields) ⇒ LinkedinParser
constructor
A new instance of LinkedinParser.
- #parse ⇒ Object
-
#results_by_job ⇒ Object
Return results with new item for each job.
-
#results_by_person ⇒ Object
Return results in nested JSON.
Constructor Details
#initialize(profile, profile_url, crawler_fields) ⇒ LinkedinParser
Returns a new instance of LinkedinParser.
11 12 13 14 15 16 |
# File 'lib/linkedinparser.rb', line 11 def initialize(profile, profile_url, crawler_fields) @profile = profile @profile_url = profile_url @crawler_fields = crawler_fields parse end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/linkedinparser.rb', line 18 def parse # Get details about the person begin p = PersonalInfo.new(@profile, @profile_url) @personal_info = p.get_personal_info @personal_info.merge!({parsing_failed: false}) rescue # Handle failed parsing @personal_info = { profile_url: @profile_url, full_html: @profile, parsing_failed: true } end # Get job info begin j = Jobs.new(@profile) @job_info = j.get_jobs rescue # Handle failed job parsing @job_info = {job_parsing_failed: true} end end |
#results_by_job ⇒ Object
Return results with new item for each job
42 43 44 45 46 47 48 49 |
# File 'lib/linkedinparser.rb', line 42 def results_by_job output = Array.new @job_info.each do |job| output.push(job.merge!(@personal_info).merge!(@crawler_fields)) end JSON.pretty_generate(output) end |
#results_by_person ⇒ Object
Return results in nested JSON
52 53 54 55 56 57 |
# File 'lib/linkedinparser.rb', line 52 def results_by_person output = @personal_info output[:jobs] = @job_info output.merge!(@crawler_fields) JSON.pretty_generate(output) end |