ruby_qb101 0.3.0 → 0.4.0

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: f0f3b24e3a7fc32eb8659469b18476223bdabc2f7cf823fafc5940775fcdbb3c
4
- data.tar.gz: 54e8190b0aef0b0d224009ed39a5e89c8a029111de268d0b6047f58e83b2da0c
3
+ metadata.gz: f95ed43b8b9f7663bd62e4b6d6794ffef6ff2a3d88be2109c9efafc6e301ac01
4
+ data.tar.gz: 3a2055303a1d1be1428293ca0331b7096e82866a32e8fca7671f96854923bdf2
5
5
  SHA512:
6
- metadata.gz: 8ce8fb423e811d5c0ddb10227c0dd0a2c69742cdcdb6e5777207d0f04f6cae6bbdeabfba90eda5b841aa985fa8fb97fb325e010d39b85680c3e92de7f2fb1bf4
7
- data.tar.gz: af26c2c91c18e8416cc975912521663c24d9ce3431e580b748514bd7548650da98dd325d430f697fddd0ac8caba5ec228b8bae2abc53e1ef13f8d972fd91595d
6
+ metadata.gz: a670add09644a3bca2aa189ca9732286667302a2da646d7a8dbee9f7fda5a03bae309e13ccfa43d144b123be33c4d94b694de3b6c8306934f0c285d848b0d517
7
+ data.tar.gz: f7e1f95db2e920ab696f78182578e90b76048b6ec71c22d0a41f09d0dd6ad7b6a2dba359103718e025764f0c021df0cd344bd3bb839bd79395d4c4fd2dc711d2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/ruby_qb101.rb CHANGED
@@ -25,7 +25,7 @@ class Ruby_Qb101
25
25
  @px = PolyrexHeadings.new(s, debug: false).to_polyrex
26
26
 
27
27
  end
28
-
28
+
29
29
  def question(id)
30
30
 
31
31
  found = @px.find_by_id(id.to_s)
@@ -57,6 +57,17 @@ class Ruby_Qb101
57
57
  Kramdown::Document.new(s).to_html
58
58
  end
59
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
68
+
69
+ end
70
+
60
71
  def to_toc()
61
72
  Yatoc.new(self.to_html(), min_sections: 1)
62
73
  end
@@ -69,6 +80,8 @@ end
69
80
 
70
81
  class Ruby_Ab101
71
82
 
83
+ # note: the ab_xml file can be in CGRecorder log XML format
84
+
72
85
  def initialize(qb_txt, ab_xml=nil, filepath: '.', debug: false)
73
86
 
74
87
  @debug = debug
@@ -81,7 +94,7 @@ class Ruby_Ab101
81
94
 
82
95
  @qb.questions.each {|q| @dx.create({question: q}) }
83
96
 
84
- if ab_xml then
97
+ if ab_xml and File.exist?(ab_xml) then
85
98
 
86
99
  dx = Dynarex.new(ab_xml)
87
100
 
@@ -90,16 +103,36 @@ class Ruby_Ab101
90
103
 
91
104
  @qb.questions.each do |q|
92
105
 
93
- found = dx.find_by_question q
94
-
95
- if found then
96
- rx = @dx.find_by_question q
97
- rx.answer = found.answer
98
- end
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
99
132
 
100
133
  end
101
134
 
102
- @dx.save ab_xml
135
+ #@dx.save ab_xml
103
136
 
104
137
  end
105
138
 
@@ -118,8 +151,11 @@ class Ruby_Ab101
118
151
  puts 'answers: ' + answers.inspect if @debug
119
152
 
120
153
  doc.root.xpath('//p').each.with_index do |para, i|
121
- e = Rexle::Element.new('p', attributes: {class: 'answer'}).add_text answers[i]
154
+
155
+ e = Rexle::Element.new('p', attributes: {class: 'answer'})\
156
+ .add_text answers[i]
122
157
  para.insert_after e
158
+
123
159
  end
124
160
 
125
161
  doc.root.xml pretty: true
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -36,7 +36,7 @@ cert_chain:
36
36
  bGVzx0RTtnomJUcww7L+cStXvNaGrg+DX+sCtqD5OMHyGROrZb0UHBgTZixAfZGU
37
37
  zfFnOLNq11nlIwZsUbPNwuNZQVZuB+GhTGc=
38
38
  -----END CERTIFICATE-----
39
- date: 2023-02-07 00:00:00.000000000 Z
39
+ date: 2023-02-14 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yatoc
@@ -58,26 +58,6 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.3.5
61
- - !ruby/object:Gem::Dependency
62
- name: polyrex-headings
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '0.3'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 0.3.0
71
- type: :runtime
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - "~>"
76
- - !ruby/object:Gem::Version
77
- version: '0.3'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 0.3.0
81
61
  description:
82
62
  email: digital.robertson@gmail.com
83
63
  executables: []
metadata.gz.sig CHANGED
Binary file