TriviaMD 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trivia_parser.rb +18 -34
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaa9f99ee0dbed631214a87e322f9e5a1e060e80468c2aa9bab0fb42c56aaa58
4
- data.tar.gz: 7a46023d6944327e917686fc40e421ea80d9bd021dc51fd4dd2e77c6647e1558
3
+ metadata.gz: 19835c608ce43770c06cb5445f861fbcc0bff7cc8c21fc6f00f13e6f6c31b557
4
+ data.tar.gz: bd1ad6450a61bda0422c1c4dfeec351306d2744c1a902a3f6e3aee8b02d25ff1
5
5
  SHA512:
6
- metadata.gz: 07e955e9bd7929ab1adc1934a7a74e1dff752ac199d5d859aae16057c8a99446a5c7e2bd32280ccaf3d63d60dd73f32e698642716b4b143e16c434985f4c0f4e
7
- data.tar.gz: b979eb1de13ef3b65bb79ab04b4e5959b294ecb7171c503268d181e724f36d3867fd89ce8e2c9e60580d906ac2e457f81f7ec18d7681f8b56cb21e77683aba42
6
+ metadata.gz: 1861a36257a03a037e77c88fc7d425d799687f4039c07e77b2280c6e16d5c8a37e8b2039b5b4b5b26870f813119f7a8d1e4be7f8ec8b559309c46a33625304b4
7
+ data.tar.gz: 4173ebda5265d03df1532900ff5400c8b38c106302d4cfe053a08ba41be06e9a83f25b0edebd313ee1913a5207e8efcba352a359e011329a82d0712fdc1b5c82
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.3
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