Class: Avmtrf1::Forponto::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/forponto/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_url, matricula, codigo) ⇒ Session

Returns a new instance of Session.



10
11
12
13
14
15
16
17
# File 'lib/avmtrf1/forponto/session.rb', line 10

def initialize(root_url, matricula, codigo)
  @root_url = root_url
  @matricula = matricula
  @codigo = codigo
  @sub = ::Aranha::Selenium::Session.new(
    user_agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'
  )
end

Instance Attribute Details

#codigoObject (readonly)

Returns the value of attribute codigo.



8
9
10
# File 'lib/avmtrf1/forponto/session.rb', line 8

def codigo
  @codigo
end

#matriculaObject (readonly)

Returns the value of attribute matricula.



8
9
10
# File 'lib/avmtrf1/forponto/session.rb', line 8

def matricula
  @matricula
end

#root_urlObject (readonly)

Returns the value of attribute root_url.



8
9
10
# File 'lib/avmtrf1/forponto/session.rb', line 8

def root_url
  @root_url
end

#subObject (readonly)

Returns the value of attribute sub.



8
9
10
# File 'lib/avmtrf1/forponto/session.rb', line 8

def sub
  @sub
end

Instance Method Details

#go_to_login_formObject



19
20
21
22
# File 'lib/avmtrf1/forponto/session.rb', line 19

def 
  sub.navigate.to root_url
  sub.wait_for_click(xpath: '//a[text() = "COLABORADOR"]')
end

#interval_data(start_date, end_date) ⇒ Object



33
34
35
36
37
# File 'lib/avmtrf1/forponto/session.rb', line 33

def interval_data(start_date, end_date)
  tempfile = '/tmp/forponto.html'
  ::File.write(tempfile, interval_source_code(start_date, end_date))
  ::Avmtrf1::Forponto::Parsers::Espelho.new("file://#{tempfile}").data
end

#interval_source_code(start_date, end_date) ⇒ Object



39
40
41
42
43
44
# File 'lib/avmtrf1/forponto/session.rb', line 39

def interval_source_code(start_date, end_date)
  (start_date, end_date)
  sub.switch_to.frame(sub.wait_for_element(xpath: '//frame[@name="topFrame"]'))
  sub.wait_for_element(xpath: '//form[@name="frmjustificativa"]')
  sub.current_source
end

#login(start_date, end_date) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/avmtrf1/forponto/session.rb', line 24

def (start_date, end_date)
  
  
  
  (start_date)
  (end_date)
  sub.wait_for_click(xpath: '//input[@name="ok"]')
end

#login_fill_codigoObject



50
51
52
# File 'lib/avmtrf1/forponto/session.rb', line 50

def 
  sub.wait_for_element(xpath: '//input[@name="deEdtFunConsulta"]').send_keys(codigo)
end

#login_fill_end_date(end_date) ⇒ Object



60
61
62
63
64
# File 'lib/avmtrf1/forponto/session.rb', line 60

def (end_date)
  sub.wait_for_element(xpath: '//input[@name="deEdtDataAte"]').send_keys(
    end_date.strftime('%d/%m/%Y')
  )
end

#login_fill_matriculaObject



46
47
48
# File 'lib/avmtrf1/forponto/session.rb', line 46

def 
  sub.wait_for_element(xpath: '//input[@name="deEdtFunCrachaSel"]').send_keys(matricula)
end

#login_fill_start_date(start_date) ⇒ Object



54
55
56
57
58
# File 'lib/avmtrf1/forponto/session.rb', line 54

def (start_date)
  sub.wait_for_element(xpath: '//input[@name="deEdtDataDe"]').send_keys(
    start_date.strftime('%d/%m/%Y')
  )
end