ruby_qb101 0.2.0 → 0.3.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: 2c606fe457d92b06eee6014a642500016f4a2d95f981b5f2cec5ff0b2205df1e
4
- data.tar.gz: a8cd2544671cdf4663a38f214295d0ce122e5c40a1ea36e13a8ed700b12c4f96
3
+ metadata.gz: f0f3b24e3a7fc32eb8659469b18476223bdabc2f7cf823fafc5940775fcdbb3c
4
+ data.tar.gz: 54e8190b0aef0b0d224009ed39a5e89c8a029111de268d0b6047f58e83b2da0c
5
5
  SHA512:
6
- metadata.gz: 225a7f5988f5b3976f5db04f36d93cfb1f79c6bef45c76cfbf9e9d34ebecd276d650112cb7eefe5a443bf29478ced234df8713fcaed10e0085cdeb80819c2653
7
- data.tar.gz: b8f582f0a6681394669c934482dc65352ec40a54a2ee51d4eec4edb579a87b24f4b98f8f7bddc1bf7a9cfcc5c18e5728ce6dc52f9e96642d535e8ebe7938bf9e
6
+ metadata.gz: 8ce8fb423e811d5c0ddb10227c0dd0a2c69742cdcdb6e5777207d0f04f6cae6bbdeabfba90eda5b841aa985fa8fb97fb325e010d39b85680c3e92de7f2fb1bf4
7
+ data.tar.gz: af26c2c91c18e8416cc975912521663c24d9ce3431e580b748514bd7548650da98dd325d430f697fddd0ac8caba5ec228b8bae2abc53e1ef13f8d972fd91595d
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,4 @@
1
- ke��Al�\g���eB�����Y�>K���n��^#�&�����J����z��Pɜ��������\e�w� �"M���M�+u1���sd{����_����ˤɄ`���d]ݤ]�����u��.����6Cd���!����a� 젯�i��=?��+���{��ߌ���}��ɘ �#�}�xm*e׏d�s�w��#l�.�ֳ���P���
2
- ��3��'l ����� ���:n���H���US�ń+>j;\�HE;���3�� Jnn�x�Q8����-\�<�0ӡ����c�nD��>��0�?UJ%_�Ҙ{�A��� ��M��%�1V߳���.�sNQ&%$��`ƿp.zGkiq�O�
1
+ F���S{�͐��1l'��?��Z)Dy�K��و'���"��MH7ӳ����(���P����%Ok��8��H Ei��"���+�U5 �>%�fj���)�&4t>
2
+ �&"�9����7f�c'�J��J��nsvv�[:����t��� X���x����'v�c�� K�, +���L�HUi���{�vq QEEo��f����r��NJ*)/�%�`K������7��kW.����@��v
3
+ #���j�����1h8�#���!8�][*�f�]ϲ��+җ��
4
+ xJ�=c��H���T�������^m��!|��{cf���X�&�BԜ�~0L��T~�$p�,k�* J�Ԧ�� .���7+�(Л PLc����
data/data/ruby_qb101.txt CHANGED
@@ -1,22 +1,20 @@
1
1
  <?ph schema="book[title,tags]/section[x]"?>
2
2
 
3
3
  title: Questions to ask when learning the programming language Ruby
4
- tags: ruby learning book questions answers
4
+ tags: ruby learning book questions answers chatgpt
5
5
 
6
- # Questions to ask when learning the programming language Ruby
6
+ # Ruby: Questions
7
7
 
8
8
  ## Introduction to Programming
9
9
 
10
10
  Write a table of contents for a programming language
11
-
12
11
  What is an expression in a programming language?
13
-
14
12
  What is a statement in a programming language?
15
13
 
16
14
 
17
15
  ## Data types
18
16
 
17
+ What are the different data types in the programming language Ruby?
19
18
  Give me an example of using an integer in the programming language Ruby.
20
-
21
19
  Give me an example of using a boolean in the programming language Ruby.
22
20
 
data/lib/ruby_qb101.rb CHANGED
@@ -3,11 +3,16 @@
3
3
  # file: ruby_qb101.tb
4
4
 
5
5
  # Description: Ruby related questions to ask Chat GPT. #experimental
6
+ # see https://github.com/jrobertson/ruby_qb101/blob/main/data/ruby_qb101.txt for questions used
6
7
 
7
8
  require 'yatoc'
8
9
  require 'polyrex-headings'
9
10
 
10
11
 
12
+ # This file contains 2 classes, the question book class and
13
+ # the answer book class.
14
+
15
+
11
16
  class Ruby_Qb101
12
17
 
13
18
  def initialize(questions_file=nil)
@@ -29,13 +34,27 @@ class Ruby_Qb101
29
34
  end
30
35
 
31
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
32
42
 
43
+ def tags()
44
+ @px.summary.tags
45
+ end
46
+
47
+ def title()
48
+ @px.summary.title
49
+ end
50
+
33
51
  def to_md()
34
52
  @questions
35
53
  end
36
54
 
37
55
  def to_html()
38
- Kramdown::Document.new(@questions).to_html
56
+ s = @questions.strip.gsub(/^([^\n#].[^\n]+)[\n]+/,'\1' + "\n\n")
57
+ Kramdown::Document.new(s).to_html
39
58
  end
40
59
 
41
60
  def to_toc()
@@ -48,6 +67,66 @@ class Ruby_Qb101
48
67
 
49
68
  end
50
69
 
51
- #qb = Ruby_Qb101.new()
52
- #qb.to_md
53
- #qb.question('7')
70
+ class Ruby_Ab101
71
+
72
+ def initialize(qb_txt, ab_xml=nil, filepath: '.', debug: false)
73
+
74
+ @debug = debug
75
+
76
+ @qb = Ruby_Qb101.new(qb_txt)
77
+
78
+ @dx = Dynarex.new('book[title, tags]/item(question, answer)')
79
+ @dx.title = @qb.title
80
+ @dx.tags = @qb.tags
81
+
82
+ @qb.questions.each {|q| @dx.create({question: q}) }
83
+
84
+ if ab_xml then
85
+
86
+ dx = Dynarex.new(ab_xml)
87
+
88
+ # using each question, find the associated answer and
89
+ # add it the main record
90
+
91
+ @qb.questions.each do |q|
92
+
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
99
+
100
+ end
101
+
102
+ @dx.save ab_xml
103
+
104
+ end
105
+
106
+ end
107
+
108
+ def save(filename)
109
+ @dx.save filename
110
+ end
111
+
112
+ def to_html()
113
+
114
+ doc = Rexle.new('<body>' + @qb.to_html.gsub(/<p>[^>]+>/,'<div>\0</div>') \
115
+ + '</body>')
116
+ answers = @dx.all.map(&:answer)
117
+
118
+ puts 'answers: ' + answers.inspect if @debug
119
+
120
+ doc.root.xpath('//p').each.with_index do |para, i|
121
+ e = Rexle::Element.new('p', attributes: {class: 'answer'}).add_text answers[i]
122
+ para.insert_after e
123
+ end
124
+
125
+ doc.root.xml pretty: true
126
+ end
127
+
128
+ def to_xml()
129
+ @dx.to_xml(pretty: true)
130
+ end
131
+
132
+ 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.2.0
4
+ version: 0.3.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-06 00:00:00.000000000 Z
39
+ date: 2023-02-07 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yatoc
metadata.gz.sig CHANGED
Binary file