class MyUniversalJobsMatch

Public Class Methods

new(filepath: '') click to toggle source
# File lib/myuniversaljobsmatch.rb, line 24
def initialize(filepath: '')

  @filepath = filepath

  @url_base = 'https://findajob.dwp.gov.uk/'
  
  @dx = Dynarex.new 'ujm[title,tags]/item(job_id, title, ' + \
      'description, posting_date, company, location, industries, job_type)'

end

Public Instance Methods

dynarex() click to toggle source
# File lib/myuniversaljobsmatch.rb, line 35
def dynarex()
  @dx
end
query(id) click to toggle source
# File lib/myuniversaljobsmatch.rb, line 115
def query(id)

  doc = Nokorexi.new(@url_base + 'details/' + id).to_doc    
  
  title = doc.root.text('head/title')
  
  rows = doc.root.xpath('//table[1]/tbody/tr')
  
  h = rows.map do |tr|
    
    [
      tr.text('th').downcase.rstrip[0..-2].gsub(/ +/,'_').to_sym, 
      tr.text('td').to_s
    ]
    
  end.to_h

  h[:description] = doc.root.element('//div[@itemprop="description"]').xml\
      .gsub(/<br *\/> */,"\n").gsub(/<\/?[^\>]+\/?>/,'').strip    
  
  h[:posting_date] = h[:posting_date].to_date
  h[:closing_date] = h[:closing_date].to_date
  
  {title: title}.merge(h)
  
end