Class: SecurityClearedJobsComParser
- Inherits:
-
Object
- Object
- SecurityClearedJobsComParser
- Includes:
- FailureHandler
- Defined in:
- lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb
Instance Method Summary collapse
-
#closing_date ⇒ Object
Get the date it closes.
-
#company_name ⇒ Object
Get the name of the company.
-
#contact_person ⇒ Object
Get the contact person.
-
#employment_status ⇒ Object
Get the employment status.
-
#get_element(field_name) ⇒ Object
Get the element for the field.
-
#initialize(url, html, requests = nil) ⇒ SecurityClearedJobsComParser
constructor
A new instance of SecurityClearedJobsComParser.
-
#job_category ⇒ Object
Gets the sector of the job.
-
#job_description ⇒ Object
Get the job description.
-
#job_description_plaintext ⇒ Object
Get the job description without html.
-
#job_number ⇒ Object
Get the job number.
-
#job_title ⇒ Object
Get the job title.
-
#location ⇒ Object
Get the location.
-
#parse ⇒ Object
Parse the job listing.
-
#posting_date ⇒ Object
Get the posting date.
-
#required_clearance ⇒ Object
Gets the clearance level required.
-
#salary ⇒ Object
Get the salary.
Methods included from FailureHandler
Constructor Details
#initialize(url, html, requests = nil) ⇒ SecurityClearedJobsComParser
Returns a new instance of SecurityClearedJobsComParser.
9 10 11 12 13 14 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 9 def initialize(url, html, requests=nil) @url = url @requests = requests @html = html @page = Nokogiri::HTML.parse(@html) end |
Instance Method Details
#closing_date ⇒ Object
Get the date it closes
66 67 68 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 66 def closing_date Date.parse(get_element("Closes")) end |
#company_name ⇒ Object
Get the name of the company
46 47 48 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 46 def company_name @page.css("div.cf[itemprop='hiringOrganization']")[0].css("span[itemprop='name']").text end |
#contact_person ⇒ Object
Get the contact person
76 77 78 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 76 def contact_person get_element("Contact") end |
#employment_status ⇒ Object
Get the employment status
81 82 83 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 81 def employment_status get_element("Job Type") end |
#get_element(field_name) ⇒ Object
Get the element for the field
111 112 113 114 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 111 def get_element(field_name) element = @page.css("div.cf").select{|d| d.text.include?(field_name)} element[0].css("dd").text.strip.lstrip.gsub(/\s+/, " ") if !element.empty? end |
#job_category ⇒ Object
Gets the sector of the job
91 92 93 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 91 def job_category get_element("Sector").split(", ") end |
#job_description ⇒ Object
Get the job description
101 102 103 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 101 def job_description @page.css("div[itemprop='description']").to_html end |
#job_description_plaintext ⇒ Object
Get the job description without html
106 107 108 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 106 def job_description_plaintext Nokogiri::HTML.parse(job_description.gsub('<br />',"\n").gsub('<br>', "\n").gsub('<br/>', "\n")).text end |
#job_number ⇒ Object
Get the job number
71 72 73 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 71 def job_number get_element("Ref") end |
#job_title ⇒ Object
Get the job title
96 97 98 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 96 def job_title @page.css("h1[itemprop='title']").text end |
#location ⇒ Object
Get the location
51 52 53 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 51 def location get_element("Location") end |
#parse ⇒ Object
Parse the job listing
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 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 17 def parse begin return { url: @url, company_name: company_name, location: location, salary: salary, posting_date: posting_date, closing_date: closing_date, job_number: job_number, contact_person: contact_person, employment_status: employment_status, required_clearance: required_clearance, job_category: job_category, job_title: job_title, job_description: job_description, job_description_plaintext: job_description_plaintext, html: @html } rescue @i += 1 if @i < 10 @html = Nokogiri::HTML.parse(get_retry(@url, @requests, @i)) parse end end end |
#posting_date ⇒ Object
Get the posting date
61 62 63 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 61 def posting_date Date.parse(get_element("Posted")) end |
#required_clearance ⇒ Object
Gets the clearance level required
86 87 88 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 86 def required_clearance get_element("Clearance Level").split(", ") end |
#salary ⇒ Object
Get the salary
56 57 58 |
# File 'lib/securityclearedjobscom/security_cleared_jobs_com_parser.rb', line 56 def salary get_element("Salary") end |