Class: Grade

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

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ Grade

Returns a new instance of Grade.



33
34
35
36
# File 'lib/academico.rb', line 33

def initialize(agent)
  @agent = agent
  @grade_selector =  'table > tbody tr:nth-child(2) > td > table > tbody > tr.conteudoTexto'
end

Instance Method Details

#create_table(rows) ⇒ Object



43
44
45
46
# File 'lib/academico.rb', line 43

def create_table(rows)
  Terminal::Table.new :rows => rows,
                      :headings =>['Matéria', '1ºBi', '2ºBi', 'MS1', '3ºBi', '4ºBi', 'MS2', 'Final']
end

#extractObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/academico.rb', line 52

def extract
  rows = []
  line = 1
  @agent.all(@grade_selector).each do |tr|
    all_tds = tr.all('td')
    info = []
    [0, 5, 7, 9, 12, 14, 18, 22].each do |field|
      n = all_tds[field].text
      if field != 0
        if n.to_f >= 6.0
          n = "\033[32m#{n}\033[m"
        else
          n = "\033[31m#{n}\033[m"
        end
      end
      info << n
    end
    rows << info
    line = line.next
  end
  rows
end

#go_to_pageObject



48
49
50
# File 'lib/academico.rb', line 48

def go_to_page
  @agent.visit '/qacademico/index.asp?t=2032'
end

#printable_gradeObject



38
39
40
41
# File 'lib/academico.rb', line 38

def printable_grade
  go_to_page
  create_table extract
end