Class: Ruby_Qb101
- Inherits:
-
Object
- Object
- Ruby_Qb101
- Defined in:
- lib/ruby_qb101.rb
Instance Method Summary collapse
-
#initialize(questions_file = nil) ⇒ Ruby_Qb101
constructor
A new instance of Ruby_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) ⇒ Ruby_Qb101
Returns a new instance of Ruby_Qb101.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_qb101.rb', line 18 def initialize(questions_file=nil) questions_file ||= File.join(File.dirname(__FILE__), '..', 'data', 'ruby_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
29 30 31 32 33 34 |
# File 'lib/ruby_qb101.rb', line 29 def question(id) found = @px.find_by_id(id.to_s) found.x if found end |
#questions ⇒ Object
38 39 40 41 |
# File 'lib/ruby_qb101.rb', line 38 def questions() doc = Rexle.new('<root>' + self.to_html + '</root>') a = doc.root.xpath('//p/text()').map(&:to_s) end |
#tags ⇒ Object
43 44 45 |
# File 'lib/ruby_qb101.rb', line 43 def () @px.summary. end |
#title ⇒ Object
47 48 49 |
# File 'lib/ruby_qb101.rb', line 47 def title() @px.summary.title end |
#to_html ⇒ Object
55 56 57 58 |
# File 'lib/ruby_qb101.rb', line 55 def to_html() s = @questions.strip.gsub(/^([^\n#].[^\n]+)[\n]+/,'\1' + "\n\n") Kramdown::Document.new(s).to_html end |
#to_md ⇒ Object
51 52 53 |
# File 'lib/ruby_qb101.rb', line 51 def to_md() @questions end |
#to_prompts ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_qb101.rb', line 60 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
71 72 73 |
# File 'lib/ruby_qb101.rb', line 71 def to_toc() Yatoc.new(self.to_html(), min_sections: 1) end |
#to_xml ⇒ Object
75 76 77 |
# File 'lib/ruby_qb101.rb', line 75 def to_xml() @px.to_xml(pretty: true) end |