Class: Qb101
- Inherits:
-
Object
- Object
- Qb101
- Defined in:
- lib/qb101.rb
Instance Method Summary collapse
-
#initialize(questions_file = nil) ⇒ Qb101
constructor
A new instance of Qb101.
- #question(id) ⇒ Object (also: #q)
- #questions ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #to_html ⇒ Object
- #to_md ⇒ Object
- #to_prompts ⇒ Object
- #to_toc ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(questions_file = nil) ⇒ Qb101
Returns a new instance of Qb101.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/qb101.rb', line 21 def initialize(questions_file=nil) questions_file ||= File.join(File.dirname(__FILE__), '..', 'data', 'qb101.txt') s = File.read(questions_file) @questions = s[/#.*/m] @px = PolyrexHeadings.new(s, debug: false).to_polyrex end |
Instance Method Details
#question(id) ⇒ Object Also known as: q
32 33 34 35 36 37 |
# File 'lib/qb101.rb', line 32 def question(id) found = @px.find_by_id(id.to_s) found.x if found end |
#questions ⇒ Object
41 42 43 44 |
# File 'lib/qb101.rb', line 41 def questions() doc = Rexle.new('<root>' + self.to_html + '</root>') a = doc.root.xpath('//p/text()').map(&:to_s) end |
#tags ⇒ Object
46 47 48 |
# File 'lib/qb101.rb', line 46 def () @px.summary. end |
#title ⇒ Object
50 51 52 |
# File 'lib/qb101.rb', line 50 def title() @px.summary.title end |
#to_html ⇒ Object
58 59 60 61 |
# File 'lib/qb101.rb', line 58 def to_html() s = @questions.strip.gsub(/^([^\n#].[^\n]+)[\n]+/,'\1' + "\n\n") Kramdown::Document.new(s).to_html end |
#to_md ⇒ Object
54 55 56 |
# File 'lib/qb101.rb', line 54 def to_md() @questions end |
#to_prompts ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/qb101.rb', line 63 def to_prompts() # generates a Dynarex file for use with ChatAway class in ChaptGpt2023 dx = Dynarex.new('prompts/entry(prompt,type, redo)') questions().each {|x| dx.create({prompt: x, type: 'completion'}) } return dx end |
#to_toc ⇒ Object
74 75 76 |
# File 'lib/qb101.rb', line 74 def to_toc() Yatoc.new(self.to_html(), min_sections: 1) end |
#to_xml ⇒ Object
78 79 80 |
# File 'lib/qb101.rb', line 78 def to_xml() @px.to_xml(pretty: true) end |