TriviaMD 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quizzes_v1.rb +3 -1
- data/lib/trivia_parser.rb +18 -34
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea7d8b0baa803ab62daaf63ac882c723e13ee9b2e7eb6a8558997516d2290093
|
4
|
+
data.tar.gz: 3601c0ae381b8b9ad0f0a04404094b371afa2f45e32449ce0035500390463df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c988e5b9a698b8477a4b276ac84853131a7cd9e261d3131405ed6dab8902c0533c16340ac1728144560d6c6d3bcaefa21035fa4a53e5c4330a331d0945e53f47
|
7
|
+
data.tar.gz: f1c9ff7f1cddbc94885dd402f90e02facb6e8aa76d08031689dc86669a6bd2ea6adbf37af4ac8b3cbd0eef94bb761afc26d8addc9767e311f335b0daee1bed03
|
data/lib/quizzes_v1.rb
CHANGED
@@ -38,7 +38,9 @@ class QuizzesV1
|
|
38
38
|
body = {
|
39
39
|
question: {
|
40
40
|
question_text: question["question"],
|
41
|
-
question_type: "multiple_answers_question"
|
41
|
+
question_type: "multiple_answers_question",
|
42
|
+
neutral_comments: question["reason"],
|
43
|
+
points_possible: 1
|
42
44
|
}
|
43
45
|
}
|
44
46
|
body[:question][:answers] = question["answers"].map do |a|
|
data/lib/trivia_parser.rb
CHANGED
@@ -6,37 +6,15 @@ class TriviaParser
|
|
6
6
|
@debug = debug
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
def event_trivia_header(c)
|
11
|
-
c.type == :header && c.options[:level] == 2 && c.options[:raw_text] == "Trivia"
|
12
|
-
end
|
13
|
-
|
14
|
-
def event_header(c)
|
15
|
-
c.type == :header
|
16
|
-
end
|
17
|
-
|
18
|
-
def event_reason(c)
|
19
|
-
c.type == :p && c.children.first.type == :codespan
|
20
|
-
end
|
21
|
-
|
22
|
-
def event_answers(c)
|
23
|
-
c.type == :ul
|
24
|
-
end
|
25
|
-
|
26
|
-
def event_question(c)
|
27
|
-
c.type == :blockquote
|
28
|
-
end
|
29
|
-
|
30
9
|
def get_event(c)
|
31
|
-
return :event_trivia_header if
|
32
|
-
return :event_header if
|
33
|
-
return :event_reason if
|
34
|
-
return :event_answers
|
35
|
-
return :event_question if
|
36
|
-
return :no_event
|
10
|
+
return { type: :event_trivia_header } if c.type == :header && c.options[:level] == 2 && c.options[:raw_text] == "Trivia"
|
11
|
+
return { type: :event_header } if c.type == :header
|
12
|
+
return { type: :event_reason, payload: { reason: c.children.first.value } } if c.type == :p && c.children.first.type == :codespan
|
13
|
+
return { type: :event_answers, payload: { answers: parse_answers(c) } } if c.type == :ul
|
14
|
+
return { type: :event_question, payload: { question: c.children.first.children.first.value } } if c.type == :blockquote
|
15
|
+
return { type: :no_event }
|
37
16
|
end
|
38
17
|
|
39
|
-
|
40
18
|
def parse_answers(c)
|
41
19
|
c.children.map do |li|
|
42
20
|
head = li.children.first.children.first
|
@@ -52,40 +30,46 @@ class TriviaParser
|
|
52
30
|
end
|
53
31
|
end
|
54
32
|
end
|
33
|
+
|
55
34
|
def parse
|
56
35
|
@doc = Kramdown::Document.new(@file)
|
57
36
|
state = :not_found
|
58
37
|
questions = []
|
59
38
|
question = {}
|
60
|
-
|
39
|
+
|
40
|
+
puts '-------------------------------------------' if @debug
|
41
|
+
|
61
42
|
@doc.root.children.each do |c|
|
62
|
-
p [state, c.type, get_event(c)]
|
63
43
|
event = get_event(c)
|
44
|
+
puts [state, c.type, event] if @debug
|
64
45
|
|
65
|
-
case event
|
46
|
+
case event[:type]
|
66
47
|
when :event_trivia_header
|
67
48
|
state = :trivia_started
|
68
49
|
question = {}
|
69
50
|
when :event_reason
|
70
51
|
if state == :reason_parsing
|
71
|
-
question[:reason] =
|
52
|
+
question[:reason] = event[:payload][:reason]
|
72
53
|
state = :trivia_started
|
73
54
|
end
|
74
55
|
when :event_answers
|
75
56
|
if state == :answer_parsing
|
76
|
-
question[:answers] =
|
57
|
+
question[:answers] = event[:payload][:answers]
|
77
58
|
state = :reason_parsing
|
78
59
|
end
|
79
60
|
when :event_question
|
80
61
|
if state == :trivia_started || state == :reason_parsing
|
81
62
|
questions.push(question) unless question.empty?
|
82
63
|
question = {
|
83
|
-
question:
|
64
|
+
question: event[:payload][:question]
|
84
65
|
}
|
85
66
|
state = :answer_parsing
|
86
67
|
end
|
68
|
+
when :event_header
|
69
|
+
state = :not_found
|
87
70
|
end
|
88
71
|
end
|
72
|
+
|
89
73
|
questions.push(question) unless question.empty?
|
90
74
|
questions
|
91
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TriviaMD
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bence Pjatacsuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|