ruby_qb101 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/data/ruby_qb101.txt +20 -0
- data/lib/ruby_qb101.rb +95 -22
- data.tar.gz.sig +0 -0
- metadata +23 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0f3b24e3a7fc32eb8659469b18476223bdabc2f7cf823fafc5940775fcdbb3c
|
4
|
+
data.tar.gz: 54e8190b0aef0b0d224009ed39a5e89c8a029111de268d0b6047f58e83b2da0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce8fb423e811d5c0ddb10227c0dd0a2c69742cdcdb6e5777207d0f04f6cae6bbdeabfba90eda5b841aa985fa8fb97fb325e010d39b85680c3e92de7f2fb1bf4
|
7
|
+
data.tar.gz: af26c2c91c18e8416cc975912521663c24d9ce3431e580b748514bd7548650da98dd325d430f697fddd0ac8caba5ec228b8bae2abc53e1ef13f8d972fd91595d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/data/ruby_qb101.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
<?ph schema="book[title,tags]/section[x]"?>
|
2
|
+
|
3
|
+
title: Questions to ask when learning the programming language Ruby
|
4
|
+
tags: ruby learning book questions answers chatgpt
|
5
|
+
|
6
|
+
# Ruby: Questions
|
7
|
+
|
8
|
+
## Introduction to Programming
|
9
|
+
|
10
|
+
Write a table of contents for a programming language
|
11
|
+
What is an expression in a programming language?
|
12
|
+
What is a statement in a programming language?
|
13
|
+
|
14
|
+
|
15
|
+
## Data types
|
16
|
+
|
17
|
+
What are the different data types in the programming language Ruby?
|
18
|
+
Give me an example of using an integer in the programming language Ruby.
|
19
|
+
Give me an example of using a boolean in the programming language Ruby.
|
20
|
+
|
data/lib/ruby_qb101.rb
CHANGED
@@ -3,37 +3,25 @@
|
|
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
|
|
8
|
+
require 'yatoc'
|
7
9
|
require 'polyrex-headings'
|
8
10
|
|
9
|
-
QUESTIONS = <<-MARKDOWN
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# This file contains 2 classes, the question book class and
|
13
|
+
# the answer book class.
|
13
14
|
|
14
|
-
# Questions to ask when learning the programming language Ruby
|
15
|
-
|
16
|
-
## Introduction to Programming
|
17
|
-
|
18
|
-
Write a table of contents for a programming language
|
19
|
-
What is an expression in a programming language?
|
20
|
-
What is a statement in a programming language?
|
21
|
-
|
22
|
-
|
23
|
-
## Data types
|
24
|
-
|
25
|
-
Give me an example of using an integer in the programming language Ruby.
|
26
|
-
Give me an example of using a boolean in the programming language Ruby.
|
27
|
-
|
28
|
-
|
29
|
-
MARKDOWN
|
30
15
|
|
31
16
|
class Ruby_Qb101
|
32
17
|
|
33
|
-
def initialize(
|
18
|
+
def initialize(questions_file=nil)
|
19
|
+
|
20
|
+
questions_file ||= File.join(File.dirname(__FILE__), '..',
|
21
|
+
'data', 'ruby_qb101.txt')
|
34
22
|
|
35
|
-
|
36
|
-
|
23
|
+
s = File.read(questions_file)
|
24
|
+
@questions = s[/#.*/m]
|
37
25
|
@px = PolyrexHeadings.new(s, debug: false).to_polyrex
|
38
26
|
|
39
27
|
end
|
@@ -46,14 +34,99 @@ class Ruby_Qb101
|
|
46
34
|
end
|
47
35
|
|
48
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
|
49
42
|
|
43
|
+
def tags()
|
44
|
+
@px.summary.tags
|
45
|
+
end
|
46
|
+
|
47
|
+
def title()
|
48
|
+
@px.summary.title
|
49
|
+
end
|
50
|
+
|
50
51
|
def to_md()
|
51
52
|
@questions
|
52
53
|
end
|
53
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_toc()
|
61
|
+
Yatoc.new(self.to_html(), min_sections: 1)
|
62
|
+
end
|
63
|
+
|
54
64
|
def to_xml()
|
55
65
|
@px.to_xml(pretty: true)
|
56
66
|
end
|
57
67
|
|
58
68
|
end
|
59
69
|
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -36,8 +36,28 @@ cert_chain:
|
|
36
36
|
bGVzx0RTtnomJUcww7L+cStXvNaGrg+DX+sCtqD5OMHyGROrZb0UHBgTZixAfZGU
|
37
37
|
zfFnOLNq11nlIwZsUbPNwuNZQVZuB+GhTGc=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2023-02-
|
39
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yatoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.3.5
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.3'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.3.5
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: polyrex-headings
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +84,7 @@ executables: []
|
|
64
84
|
extensions: []
|
65
85
|
extra_rdoc_files: []
|
66
86
|
files:
|
87
|
+
- data/ruby_qb101.txt
|
67
88
|
- lib/ruby_qb101.rb
|
68
89
|
homepage: https://github.com/jrobertson/ruby_qb101
|
69
90
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|