Class: PnoteClient::Documents::Pnote::Problem

Inherits:
Object
  • Object
show all
Includes:
Utils::StringUtil
Defined in:
lib/pnote_client/documents/pnote/problem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StringUtil

#add_line

Constructor Details

#initialize(question: nil, answer: nil, explaination: nil, choices: nil, teacher_comments: [], tip: nil) ⇒ Problem

Returns a new instance of Problem.



12
13
14
15
16
17
18
19
20
21
# File 'lib/pnote_client/documents/pnote/problem.rb', line 12

def initialize(
  question: nil, answer: nil, explaination: nil,
  choices: nil, teacher_comments: [], tip: nil
)

  @question, @answer, @explaination, @choices, @teacher_comments, @tip =
    question, answer, explaination, choices, teacher_comments, tip
  @choice = nil
  @answer_line = nil
end

Instance Attribute Details

#explainationObject

Returns the value of attribute explaination.



9
10
11
# File 'lib/pnote_client/documents/pnote/problem.rb', line 9

def explaination
  @explaination
end

#questionObject

Returns the value of attribute question.



9
10
11
# File 'lib/pnote_client/documents/pnote/problem.rb', line 9

def question
  @question
end

#teacher_commentsObject

Returns the value of attribute teacher_comments.



10
11
12
# File 'lib/pnote_client/documents/pnote/problem.rb', line 10

def teacher_comments
  @teacher_comments
end

#tipObject

Returns the value of attribute tip.



10
11
12
# File 'lib/pnote_client/documents/pnote/problem.rb', line 10

def tip
  @tip
end

Instance Method Details

#add_answer_line(new_line) ⇒ Object



27
28
29
# File 'lib/pnote_client/documents/pnote/problem.rb', line 27

def add_answer_line(new_line)
  @answer_line = add_line(@answer_line, new_line)
end

#add_choice_line(new_line) ⇒ Object



35
36
37
# File 'lib/pnote_client/documents/pnote/problem.rb', line 35

def add_choice_line(new_line)
  @choice = add_line(@choice, new_line)
end

#add_explaination_line(new_line) ⇒ Object



31
32
33
# File 'lib/pnote_client/documents/pnote/problem.rb', line 31

def add_explaination_line(new_line)
  @explaination = add_line(@explaination, new_line)
end

#add_question_line(new_line) ⇒ Object



23
24
25
# File 'lib/pnote_client/documents/pnote/problem.rb', line 23

def add_question_line(new_line)
  @question = add_line(@question, new_line)
end

#add_teacher_comment(new_teacher_comment) ⇒ Object



52
53
54
# File 'lib/pnote_client/documents/pnote/problem.rb', line 52

def add_teacher_comment(new_teacher_comment)
  @teacher_comments << new_teacher_comment
end

#add_tip_line(new_line) ⇒ Object



56
57
58
# File 'lib/pnote_client/documents/pnote/problem.rb', line 56

def add_tip_line(new_line)
  @tip = add_line(@tip, new_line)
end

#answerObject



39
40
41
42
# File 'lib/pnote_client/documents/pnote/problem.rb', line 39

def answer
  return @answer if @answer
  return @answer_line&.match(/\s*\[정답\]\s*(.*)/).to_a[1]&.strip
end

#choicesObject



44
45
46
47
48
49
50
# File 'lib/pnote_client/documents/pnote/problem.rb', line 44

def choices
  return @choices if @choices
  return [] if @choice.nil?

  choice_number_pattern = /①|②|③|④|⑤/
  return @choice.split(choice_number_pattern).reject {|el| el.empty?}.map {|el| el.strip}
end