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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa9f99ee0dbed631214a87e322f9e5a1e060e80468c2aa9bab0fb42c56aaa58
4
- data.tar.gz: 7a46023d6944327e917686fc40e421ea80d9bd021dc51fd4dd2e77c6647e1558
3
+ metadata.gz: ea7d8b0baa803ab62daaf63ac882c723e13ee9b2e7eb6a8558997516d2290093
4
+ data.tar.gz: 3601c0ae381b8b9ad0f0a04404094b371afa2f45e32449ce0035500390463df0
5
5
  SHA512:
6
- metadata.gz: 07e955e9bd7929ab1adc1934a7a74e1dff752ac199d5d859aae16057c8a99446a5c7e2bd32280ccaf3d63d60dd73f32e698642716b4b143e16c434985f4c0f4e
7
- data.tar.gz: b979eb1de13ef3b65bb79ab04b4e5959b294ecb7171c503268d181e724f36d3867fd89ce8e2c9e60580d906ac2e457f81f7ec18d7681f8b56cb21e77683aba42
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 event_trivia_header(c)
32
- return :event_header if event_header(c)
33
- return :event_reason if event_reason(c)
34
- return :event_answers if event_answers(c)
35
- return :event_question if event_question(c)
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
- puts '-------------------------------------------'
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] = c.children.first.value
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] = parse_answers(c)
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: c.children.first.children.first.value
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.2
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-10-31 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor