class QuickExam::Analyzer

Attributes

f_corr[R]
f_ques[R]
records[R]
total_line[R]

Public Class Methods

new(file_path, f_ques:'' , f_corr:'') click to toggle source
# File lib/quick_exam/analyzer.rb, line 11
def initialize(file_path, f_ques:'' , f_corr:'')
  raise ErrorAnalyze.new('No such file') unless File.exist? file_path
  @file_path = file_path
  @f_ques = f_ques.__presence || QUESTION_MARK
  @f_corr = f_corr.__presence || CORRECT_MARK
end

Public Instance Methods

analyze() click to toggle source
# File lib/quick_exam/analyzer.rb, line 18
def analyze
  case
  when txt? then process_base_text
  when docx? then process_base_docx
  when html? then process_base_html
  end
end
docx?() click to toggle source
# File lib/quick_exam/analyzer.rb, line 34
def docx?
  File.extname(@file_path) == '.docx'
end
html?() click to toggle source
# File lib/quick_exam/analyzer.rb, line 30
def html?
  File.extname(@file_path) == '.html'
end
txt?() click to toggle source
# File lib/quick_exam/analyzer.rb, line 26
def txt?
  File.extname(@file_path) == '.txt'
end

Private Instance Methods

process_base_docx() click to toggle source
# File lib/quick_exam/analyzer.rb, line 56
def process_base_docx
  docx_analyzer = QuickExam::Analyst::BaseDocx.new(@file_path, f_ques: @f_ques, f_corr: @f_corr)
  docx_analyzer.analyze
  @records = docx_analyzer.records
  @total_line = docx_analyzer.total_line
  self
end
process_base_html() click to toggle source
# File lib/quick_exam/analyzer.rb, line 48
def process_base_html
  html_analyzer = QuickExam::Analyst::BaseHTML.new(@file_path, f_ques: @f_ques, f_corr: @f_corr)
  html_analyzer.analyze
  @records = html_analyzer.records
  @total_line = html_analyzer.total_line
  self
end
process_base_text() click to toggle source
# File lib/quick_exam/analyzer.rb, line 40
def process_base_text
  text_analyzer = QuickExam::Analyst::BaseText.new(@file_path, f_ques: @f_ques, f_corr: @f_corr)
  text_analyzer.analyze
  @records = text_analyzer.records
  @total_line = text_analyzer.total_line
  self
end