Class: Jobs
Instance Method Summary collapse
-
#company(position) ⇒ Object
Get the company for the position.
-
#current(position) ⇒ Object
Check if it is a current position or not.
-
#date_parse(date) ⇒ Object
Parse date.
-
#description(position) ⇒ Object
Get job description.
-
#end_date(position) ⇒ Object
Get end date.
-
#get_dates(position) ⇒ Object
Get dates.
-
#get_jobs ⇒ Object
Get list of jobs.
-
#initialize(profile) ⇒ Jobs
constructor
A new instance of Jobs.
- #parse_jobs ⇒ Object
-
#start_date(position) ⇒ Object
Get start date.
-
#title(position) ⇒ Object
Get the job title.
-
#work_location(position) ⇒ Object
Get location for work.
Methods included from Utilities
Constructor Details
#initialize(profile) ⇒ Jobs
Returns a new instance of Jobs.
6 7 8 9 |
# File 'lib/jobs.rb', line 6 def initialize(profile) @html = Nokogiri::HTML(profile) parse_jobs end |
Instance Method Details
#company(position) ⇒ Object
Get the company for the position
50 51 52 |
# File 'lib/jobs.rb', line 50 def company(position) position.css('h5').text end |
#current(position) ⇒ Object
Check if it is a current position or not
37 38 39 40 41 42 |
# File 'lib/jobs.rb', line 37 def current(position) if end_date(position) == "Present" return "Yes" else return "No" end end |
#date_parse(date) ⇒ Object
Parse date
83 84 85 86 87 88 89 90 |
# File 'lib/jobs.rb', line 83 def date_parse(date) begin date = date+"-01-01" if date =~ /^(19|20)\d{2}$/ return Date.parse(date) rescue return date end end |
#description(position) ⇒ Object
Get job description
55 56 57 |
# File 'lib/jobs.rb', line 55 def description(position) position.css('.description').text end |
#end_date(position) ⇒ Object
Get end date
73 74 75 76 77 78 79 80 |
# File 'lib/jobs.rb', line 73 def end_date(position) end_date = get_dates(position).text.split(' – ').last.split("(").first.strip if end_date == "Present" return end_date elsif end_date && !end_date.empty? return date_parse(end_date) end end |
#get_dates(position) ⇒ Object
Get dates
60 61 62 63 64 |
# File 'lib/jobs.rb', line 60 def get_dates(position) dates = position.css('.meta').css('.date-range') dates = position.css('.experience-date-locale') if is_empty?(dates) return dates end |
#get_jobs ⇒ Object
Get list of jobs
12 13 14 |
# File 'lib/jobs.rb', line 12 def get_jobs return @positions_list end |
#parse_jobs ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jobs.rb', line 16 def parse_jobs # Multiple html options positions = @html.css('#experience').css('.position') positions = @html.css('#background-experience').css('.current-position') + @html.css('#background-experience').css('.past-position') if is_empty?(positions) # Get lists of positions @positions_list = Array.new positions.each do |position| @positions_list.push({ title: title(position), company: company(position), description: description(position), start_date: start_date(position), end_date: end_date(position), work_location: work_location(position), current: current(position)}) end end |
#start_date(position) ⇒ Object
Get start date
67 68 69 70 |
# File 'lib/jobs.rb', line 67 def start_date(position) start_date = get_dates(position).text.split(' – ')[0] return date_parse(start_date) end |
#title(position) ⇒ Object
Get the job title
45 46 47 |
# File 'lib/jobs.rb', line 45 def title(position) position.css('h4').text end |
#work_location(position) ⇒ Object
Get location for work
93 94 95 |
# File 'lib/jobs.rb', line 93 def work_location(position) position.css('.experience-date-locale').css('.locality').text end |