@@ -14,14 +14,11 @@ def parse(content)
14
14
question = ''
15
15
empty_lines = 0
16
16
content . each_line do |line |
17
- if line . length == 0
17
+ if line . strip . empty?
18
18
empty_lines +=1
19
19
if empty_lines >= 2 && !question . empty?
20
- begin
21
- questions << build_question ( question , category , comment )
22
- rescue => e
23
- raise MoodleGiftParser ::InvalidGiftFormatError , "Error parsing question:#{ e . message } \n Question: '#{ question } '" , e . backtrace
24
- end
20
+ MoodleGiftParser . logger . debug { "Question finished: '#{ question } '" }
21
+ questions << build_question_wrapped ( question , category , comment )
25
22
26
23
question = ''
27
24
comment = ''
@@ -30,22 +27,38 @@ def parse(content)
30
27
end
31
28
32
29
if line . start_with? ( CATEGORY_PREFIX )
33
- category = line [ CATEGORY_PREFIX . length ..-1 ]
30
+ category = line [ CATEGORY_PREFIX . length ..-1 ] . strip
31
+ MoodleGiftParser . logger . debug { "Found category: '#{ category } '" }
34
32
next
35
33
end
36
34
37
35
if line . start_with? ( COMMENT_PREFIX )
38
36
#concat if multiline comment
39
37
comment = comment + line [ COMMENT_PREFIX . length ..-1 ]
38
+ MoodleGiftParser . logger . debug { "Found comment: '#{ comment . strip } '" }
40
39
next
41
40
end
42
41
43
42
question = question + line
44
43
end
45
44
45
+ if !question . empty?
46
+ MoodleGiftParser . logger . debug { "Last question finished: '#{ question } '" }
47
+ questions << build_question_wrapped ( question , category , comment )
48
+ end
49
+
46
50
return questions
47
51
end
48
52
53
+ private
54
+ def build_question_wrapped ( question , category , comment )
55
+ begin
56
+ return build_question ( question , category , comment )
57
+ rescue => e
58
+ raise MoodleGiftParser ::InvalidGiftFormatError , "Error parsing question:#{ e . message } \n Question: '#{ question } '" , e . backtrace
59
+ end
60
+ end
61
+
49
62
private
50
63
def build_question ( question_str , category , comment )
51
64
question_text = question_str . dup
0 commit comments