class QuickExam::Analyst::BaseDocx

Attributes

records[R]
total_line[R]

Public Class Methods

new(file_path, f_ques:'' , f_corr:'') click to toggle source
# File lib/quick_exam/analyst/base_docx.rb, line 13
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
  @f_corr = f_corr
  @records = QuickExam::RecordCollection.new()
end

Public Instance Methods

analyze() click to toggle source
# File lib/quick_exam/analyst/base_docx.rb, line 21
def analyze
  data_standardize
  self
rescue => e
  raise ErrorAnalyze.new('Data can not analyze')
end

Private Instance Methods

data_standardize() click to toggle source
# File lib/quick_exam/analyst/base_docx.rb, line 32
def data_standardize
  doc = Docx::Document.open(@file_path)
  data = doc.paragraphs

  @total_line = data.size
  @object = QuickExam::Record.new()

  data.each.with_index do |row, idx|
    row = row.text
    idx += 1 # The first row is 1

    if end_of_line?(idx) || end_of_one_ticket_for_next_question?(row)
      get_answer(row) # if the last line is answer then will get answer
      collect_object_ticket
    end

    next if row.__blank?

    next if get_answer(row)
    next if get_question(row)
  end
  records
end