class PnoteClient::Validators::PnoteValidator

Public Class Methods

new(pnote_document) click to toggle source
Calls superclass method
# File lib/pnote_client/validators/pnote_validator.rb, line 10
def initialize(pnote_document)
  super()
  @pnote_document = pnote_document
end

Public Instance Methods

validate() click to toggle source
# File lib/pnote_client/validators/pnote_validator.rb, line 15
def validate
  reset_errors
  validate_pnote_document
  return @errors
end

Private Instance Methods

validate_pnote_document() click to toggle source
# File lib/pnote_client/validators/pnote_validator.rb, line 23
def validate_pnote_document
  practice_number = 1

  @pnote_document.chapters.each do |chapter|
    chapter.sub_chapters.each do |sub_chapter|
      chapter.practices.each do |practice|
        validate_problem(practice, practice_number)
        practice_number += 1
      end

      sub_chapter.practices.each do |practice|
        validate_problem(practice, practice_number)
        practice_number += 1
      end
    end
  end
end
validate_problem(problem, practice_number) click to toggle source
# File lib/pnote_client/validators/pnote_validator.rb, line 41
def validate_problem(problem, practice_number)
  if problem.answer
    if problem.answer.length >= 15
      add_error(
        make_error(
          title: "문제 정답의 길이가 15자 이상입니다.",
          practice_number: practice_number,
          type: "문제 정답",
          detail: problem.answer
        )
      )
    end
  end
end