Class: Gipper::Question
- Inherits:
-
Object
- Object
- Gipper::Question
- Includes:
- SpecialCharacterHandler, Oniguruma
- Defined in:
- lib/question.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
Returns the value of attribute answer.
-
#format ⇒ Object
Returns the value of attribute format.
-
#style ⇒ Object
Returns the value of attribute style.
-
#text ⇒ Object
Returns the value of attribute text.
-
#text_post ⇒ Object
Returns the value of attribute text_post.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #find_style(answers) ⇒ Object
-
#parse(text) ⇒ Object
instance method to parse the question.
Instance Attribute Details
#answer ⇒ Object
Returns the value of attribute answer.
8 9 10 |
# File 'lib/question.rb', line 8 def answer @answer end |
#format ⇒ Object
Returns the value of attribute format.
8 9 10 |
# File 'lib/question.rb', line 8 def format @format end |
#style ⇒ Object
Returns the value of attribute style.
8 9 10 |
# File 'lib/question.rb', line 8 def style @style end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/question.rb', line 8 def text @text end |
#text_post ⇒ Object
Returns the value of attribute text_post.
8 9 10 |
# File 'lib/question.rb', line 8 def text_post @text_post end |
#title ⇒ Object
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 |