class Mwcrawler::Helpers

Helper methods used throughout the lib

Public Class Methods

format_hours(schedules, row = []) click to toggle source
# File lib/mwcrawler/helpers.rb, line 37
def self.format_hours(schedules, row = [])
  until schedules.empty?
    schedule = []
    schedule << schedules.shift # DIA
    schedule << schedules.shift # HORARIO DE INICIO
    schedule << schedules.shift # HORARIO DE FIM
    schedules.shift # RETIRANDO LIXO
    schedule << schedules.shift # LOCAL DA AULA
    row << schedule
  end
  row
end
format_teachers(teachers) click to toggle source
# File lib/mwcrawler/helpers.rb, line 50
def self.format_teachers(teachers)
  teachers.empty? ? ['A Designar'] : teachers
end
log(msg) click to toggle source
# File lib/mwcrawler/helpers.rb, line 67
def self.log(msg)
  puts msg if Options.log_enabled?
end
set_crawler(id, search_mode, options = { exact: false }) click to toggle source

MODE: TURMAS, CURSOS OU CURRICULO

# File lib/mwcrawler/helpers.rb, line 55
def self.set_crawler(id, search_mode, options = { exact: false })
  id = Campuses.id id unless options[:exact]
  url = SITE + search_mode + id.to_s
  Nokogiri::HTML(URI.parse(url).open)
end
uri_query_params(uri) click to toggle source
# File lib/mwcrawler/helpers.rb, line 71
def self.uri_query_params(uri)
  query_string = URI.parse(uri).query
  query_string.split('&').map { |param| param.split('=') }.to_h
end
write_json(file_name, object) click to toggle source
# File lib/mwcrawler/helpers.rb, line 61
def self.write_json(file_name, object)
  File.open(file_name, 'w+') do |f|
    f.write object.to_json
  end
end