Class: Gipper::Question

Inherits:
Object
  • Object
show all
Includes:
SpecialCharacterHandler, Oniguruma
Defined in:
lib/question.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answerObject

Returns the value of attribute answer.



8
9
10
# File 'lib/question.rb', line 8

def answer
  @answer
end

#formatObject

Returns the value of attribute format.



8
9
10
# File 'lib/question.rb', line 8

def format
  @format
end

#styleObject

Returns the value of attribute style.



8
9
10
# File 'lib/question.rb', line 8

def style
  @style
end

#textObject

Returns the value of attribute text.



8
9
10
# File 'lib/question.rb', line 8

def text
  @text
end

#text_postObject

Returns the value of attribute text_post.



8
9
10
# File 'lib/question.rb', line 8

def text_post
  @text_post
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/question.rb', line 8

def title
  @title
end

Instance Method Details

#find_style(answers) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/question.rb', line 27

def find_style answers
  if @text_post
    return :missing_word
  end

  answers.find_style
end

#parse(text) ⇒ Object

instance method to parse the question



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/question.rb', line 11

def parse text
  reg = ORegexp.new('(.+)(?<!\\\\)\{(?<!\\\\)(.+)\}(.*)', :options => OPTION_MULTILINE)
  matches = reg.match(text.strip).captures.map { |s| s.strip }

  @text_post = unescape(matches[2]) unless matches[2].empty?
  
  answer = matches[1]

  @answer = Gipper::Answers.new
  @answer.parse(answer)

  @format, @title, @text = to_parts(matches[0]).map { |s| unescape s}

  @style = find_style @answer
end