ruby_qb101 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f95ed43b8b9f7663bd62e4b6d6794ffef6ff2a3d88be2109c9efafc6e301ac01
4
- data.tar.gz: 3a2055303a1d1be1428293ca0331b7096e82866a32e8fca7671f96854923bdf2
3
+ metadata.gz: e1c73397fa820b39755d0b882b724f6035e1abe89ab36b073ba83affb0a9da81
4
+ data.tar.gz: c53174ec89bbe82398b7147410a5fe2a17e8d82bdb32df5c95be056ed9336ad6
5
5
  SHA512:
6
- metadata.gz: a670add09644a3bca2aa189ca9732286667302a2da646d7a8dbee9f7fda5a03bae309e13ccfa43d144b123be33c4d94b694de3b6c8306934f0c285d848b0d517
7
- data.tar.gz: f7e1f95db2e920ab696f78182578e90b76048b6ec71c22d0a41f09d0dd6ad7b6a2dba359103718e025764f0c021df0cd344bd3bb839bd79395d4c4fd2dc711d2
6
+ metadata.gz: ac956d7653a2510986952d171f0cf8f490bad312eca99cd7a042ebac904b6cdf9950a97deecfe3e63a85ef240c4f909228b9cded083890770947c6d2e4fc66de
7
+ data.tar.gz: 7ab5fb75f4c9227ddd72ea4b0aaa9219c42f0c7f154abbf72e8e659ad6419b65526511dd5c65390b2fb08bd6c4ce2a12a57f9d14cd6eb81b14ee262cbaf47e9b
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/ruby_qb101.rb CHANGED
@@ -5,164 +5,35 @@
5
5
  # Description: Ruby related questions to ask Chat GPT. #experimental
6
6
  # see https://github.com/jrobertson/ruby_qb101/blob/main/data/ruby_qb101.txt for questions used
7
7
 
8
- require 'yatoc'
9
- require 'polyrex-headings'
8
+ require 'qb101'
9
+
10
10
 
11
11
 
12
12
  # This file contains 2 classes, the question book class and
13
13
  # the answer book class.
14
14
 
15
15
 
16
- class Ruby_Qb101
16
+ class Ruby_Qb101 < Qb101
17
17
 
18
18
  def initialize(questions_file=nil)
19
19
 
20
20
  questions_file ||= File.join(File.dirname(__FILE__), '..',
21
21
  'data', 'ruby_qb101.txt')
22
22
 
23
- s = File.read(questions_file)
24
- @questions = s[/#.*/m]
25
- @px = PolyrexHeadings.new(s, debug: false).to_polyrex
26
-
27
- end
28
-
29
- def question(id)
30
-
31
- found = @px.find_by_id(id.to_s)
32
- found.x if found
33
-
34
- end
35
-
36
- alias q question
37
-
38
- def questions()
39
- doc = Rexle.new('<root>' + self.to_html + '</root>')
40
- a = doc.root.xpath('//p/text()').map(&:to_s)
41
- end
42
-
43
- def tags()
44
- @px.summary.tags
45
- end
46
-
47
- def title()
48
- @px.summary.title
49
- end
50
-
51
- def to_md()
52
- @questions
53
- end
54
-
55
- def to_html()
56
- s = @questions.strip.gsub(/^([^\n#].[^\n]+)[\n]+/,'\1' + "\n\n")
57
- Kramdown::Document.new(s).to_html
58
- end
59
-
60
- def to_prompts()
61
-
62
- # generates a Dynarex file for use with ChatAway class in ChaptGpt2023
63
- dx = Dynarex.new('prompts/entry(prompt,type, redo)')
64
-
65
- questions().each {|x| dx.create({prompt: x, type: 'completion'}) }
66
-
67
- return dx
23
+ super(questions_file)
68
24
 
69
25
  end
70
26
 
71
- def to_toc()
72
- Yatoc.new(self.to_html(), min_sections: 1)
73
- end
74
-
75
- def to_xml()
76
- @px.to_xml(pretty: true)
77
- end
78
-
79
27
  end
80
28
 
81
- class Ruby_Ab101
29
+ class Ruby_Ab101 < Ab101
82
30
 
83
31
  # note: the ab_xml file can be in CGRecorder log XML format
84
32
 
85
- def initialize(qb_txt, ab_xml=nil, filepath: '.', debug: false)
86
-
87
- @debug = debug
88
-
89
- @qb = Ruby_Qb101.new(qb_txt)
90
-
91
- @dx = Dynarex.new('book[title, tags]/item(question, answer)')
92
- @dx.title = @qb.title
93
- @dx.tags = @qb.tags
94
-
95
- @qb.questions.each {|q| @dx.create({question: q}) }
96
-
97
- if ab_xml and File.exist?(ab_xml) then
98
-
99
- dx = Dynarex.new(ab_xml)
100
-
101
- # using each question, find the associated answer and
102
- # add it the main record
103
-
104
- @qb.questions.each do |q|
105
-
106
- puts 'q: ' + q.inspect if @debug
107
-
108
- # note: the find_by ... method is passing in a regex because passing
109
- # in a String causes the xpath to execute which is known to have
110
- # a serious bug when the value contains *and*.
111
- if dx.schema =~ /question, answer/ then
112
-
113
- found = dx.find_by_question /#{q}/
114
-
115
- if found then
116
- rx = @dx.find_by_question /#{q}/
117
- rx.answer = found.answer
118
- end
119
-
120
- else
121
-
122
- #puts 'dx: ' + dx.to_xml(pretty: true) if @debug
123
- found = dx.find_by_prompt /#{q}/
124
- puts 'found: ' + found.inspect if @debug
125
-
126
- if found then
127
- rx = @dx.find_by_question /#{q}/
128
- rx.answer = found.result
129
- end
130
-
131
- end
33
+ def initialize(qb, ab_xml=nil, filepath: '.', debug: false)
132
34
 
133
- end
134
-
135
- #@dx.save ab_xml
136
-
137
- end
138
-
139
- end
140
-
141
- def save(filename)
142
- @dx.save filename
35
+ super(qb, ab_xml, filepath: filepath, debug: debug)
143
36
  end
144
-
145
- def to_html()
146
37
 
147
- doc = Rexle.new('<body>' + @qb.to_html.gsub(/<p>[^>]+>/,'<div>\0</div>') \
148
- + '</body>')
149
- answers = @dx.all.map(&:answer)
150
-
151
- puts 'answers: ' + answers.inspect if @debug
152
-
153
- doc.root.xpath('//p').each.with_index do |para, i|
154
-
155
- e = Rexle::Element.new('p', attributes: {class: 'answer'})\
156
- .add_text answers[i]
157
- para.insert_after e
158
-
159
- end
160
-
161
- doc.root.xml pretty: true
162
- end
163
-
164
- def to_xml()
165
- @dx.to_xml(pretty: true)
166
- end
167
38
 
168
39
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_qb101
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -36,28 +36,28 @@ cert_chain:
36
36
  bGVzx0RTtnomJUcww7L+cStXvNaGrg+DX+sCtqD5OMHyGROrZb0UHBgTZixAfZGU
37
37
  zfFnOLNq11nlIwZsUbPNwuNZQVZuB+GhTGc=
38
38
  -----END CERTIFICATE-----
39
- date: 2023-02-14 00:00:00.000000000 Z
39
+ date: 2023-03-15 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
- name: yatoc
42
+ name: qb101
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.3'
47
+ version: '0.2'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.3.5
50
+ version: 0.2.0
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '0.3'
57
+ version: '0.2'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 0.3.5
60
+ version: 0.2.0
61
61
  description:
62
62
  email: digital.robertson@gmail.com
63
63
  executables: []
metadata.gz.sig CHANGED
Binary file