Class: Qb101

Inherits:
Object
  • Object
show all
Defined in:
lib/qb101.rb

Instance Method Summary collapse

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

#questionsObject



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

#tagsObject



46
47
48
# File 'lib/qb101.rb', line 46

def tags()
  @px.summary.tags
end

#titleObject



50
51
52
# File 'lib/qb101.rb', line 50

def title()
  @px.summary.title
end

#to_htmlObject



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_mdObject



54
55
56
# File 'lib/qb101.rb', line 54

def to_md()
  @questions
end

#to_promptsObject



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_tocObject



74
75
76
# File 'lib/qb101.rb', line 74

def to_toc()
  Yatoc.new(self.to_html(), min_sections: 1)    
end

#to_xmlObject



78
79
80
# File 'lib/qb101.rb', line 78

def to_xml()
  @px.to_xml(pretty: true)
end