Class: QuickExam::Analyzer

Inherits:
Object show all
Includes:
Format
Defined in:
lib/quick_exam/analyzer.rb

Constant Summary

Constants included from Format

Format::ALLOWED_ELEMENTS, Format::CORRECT_MARK, Format::FOLDER_NAME_EXPORT, Format::QUESTION_MARK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Format

#correct_mark, #question_mark

Constructor Details

#initialize(file_path, f_ques: '', f_corr: '') ⇒ Analyzer

Returns a new instance of Analyzer.

Raises:



11
12
13
14
15
16
# 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

Instance Attribute Details

#f_corrObject (readonly)

Returns the value of attribute f_corr.



9
10
11
# File 'lib/quick_exam/analyzer.rb', line 9

def f_corr
  @f_corr
end

#f_quesObject (readonly)

Returns the value of attribute f_ques.



9
10
11
# File 'lib/quick_exam/analyzer.rb', line 9

def f_ques
  @f_ques
end

#recordsObject (readonly)

Returns the value of attribute records.



9
10
11
# File 'lib/quick_exam/analyzer.rb', line 9

def records
  @records
end

#total_lineObject (readonly)

Returns the value of attribute total_line.



9
10
11
# File 'lib/quick_exam/analyzer.rb', line 9

def total_line
  @total_line
end

Instance Method Details

#analyzeObject



18
19
20
21
22
23
24
# 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?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/quick_exam/analyzer.rb', line 34

def docx?
  File.extname(@file_path) == '.docx'
end

#html?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/quick_exam/analyzer.rb', line 30

def html?
  File.extname(@file_path) == '.html'
end

#txt?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/quick_exam/analyzer.rb', line 26

def txt?
  File.extname(@file_path) == '.txt'
end