Class: Jofh22::NHSScot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yml = '/tmp/tmp.yaml', ofh22_filepath = nil, cookies: nil, debug: false) ⇒ NHSScot

notes:

* the *cookies* parameter can reference a file path to save or
  read a cookie file
* the *yml* parameter refeference the YAML file containing the inputs


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jofh22.rb', line 23

def initialize(yml='/tmp/tmp.yaml', ofh22_filepath=nil,
               cookies: nil, debug: false)

  @cookies, @debug = cookies, debug
  ofh22_filepath ||= File.join(File.dirname(__FILE__), '..', 'data',
                               'nhs_scot.yaml')
  url = 'https://apply.jobs.scot.nhs.uk/register.aspx'
  cookies2 = cookies if File.exists? cookies
  @browser = browser = FerrumWizard.new(url,  headless: false,
                                        cookies: cookies2)
  sleep 1

  filepath = yml
  @h = YAML.load(File.read(filepath))

  if not @h['home_telephone'].to_s[0] == '+' then
    @h['home_telephone'] = '+' + @h['home_telephone'].to_s
  end

  @ofh22 = YAML.load(File.read(ofh22_filepath))

end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



15
16
17
# File 'lib/jofh22.rb', line 15

def browser
  @browser
end

Instance Method Details

#populate_form(cookie_filepath = @cookies) ⇒ Object

used for the registration process for new applicants



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jofh22.rb', line 48

def populate_form(cookie_filepath=@cookies)

  @ofh22.each do |key, x|

    if @debug then
      puts 'key: ' + key.inspect
      puts 'x: ' + x.inspect
    end

    type, xpath = x

    if type == :input or type == :select then
      @browser.method(type).call(xpath, @h[key.to_s])
    elsif type == :click
      @browser.method(type).call(xpath)
    end

  end

  @browser.save_cookies(cookie_filepath)
  puts 'cookies saved to ' + cookie_filepath

end

#to_hObject



72
73
74
# File 'lib/jofh22.rb', line 72

def to_h()
  @h
end

#to_ofh22Object



76
77
78
# File 'lib/jofh22.rb', line 76

def to_ofh22()
  @ofh22
end