class PnoteClient::Validators::HmlValidator
Public Class Methods
new(hml_document)
click to toggle source
Calls superclass method
# File lib/pnote_client/validators/hml_validator.rb, line 13 def initialize(hml_document) super() @hml_document = hml_document end
Public Instance Methods
validate()
click to toggle source
# File lib/pnote_client/validators/hml_validator.rb, line 18 def validate reset_errors validate_document return @errors end
Private Instance Methods
paragraph_style_name(paragraph)
click to toggle source
# File lib/pnote_client/validators/hml_validator.rb, line 70 def paragraph_style_name(paragraph) return @hml_document.styles.find {|style| style.id == paragraph.style_id }&.name end
practice_style_id()
click to toggle source
# File lib/pnote_client/validators/hml_validator.rb, line 66 def practice_style_id @practice_style_id ||= @hml_document.styles.find {|style| style.name == PnoteClient::STYLES[:practice_question] }&.id end
validate_document()
click to toggle source
# File lib/pnote_client/validators/hml_validator.rb, line 26 def validate_document practice_number = 1 @hml_document.paragraphs.each do |paragraph| next if paragraph.style_id != practice_style_id validate_paragraph(paragraph, practice_number) paragraph.endnote_paragraphs.each do |paragraph| validate_paragraph(paragraph, practice_number) end paragraph.footnote_paragraphs.each do |paragraph| validate_paragraph(paragraph, practice_number) end # 한 문제가 두 문단 이상으로 나눠진경우 # 풋노트 존재여부로 문제 완료 여부를 알 수 있음 if paragraph.footnote_paragraphs.length > 0 practice_number += 1 end end end
validate_paragraph(paragraph, practice_number)
click to toggle source
# File lib/pnote_client/validators/hml_validator.rb, line 49 def validate_paragraph(paragraph, practice_number) paragraph.elements.each do |element| if element.class == Documents::Hml::Equation element.validate.each do |error| add_error( make_error( title: error[:message], problem_number: practice_number, type: paragraph_style_name(paragraph), detail: error[:detail] ) ) end end end end