Class: Ruby_Qb101

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

Instance Method Summary collapse

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

#questionsObject



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

#tagsObject



43
44
45
# File 'lib/ruby_qb101.rb', line 43

def tags()
  @px.summary.tags
end

#titleObject



47
48
49
# File 'lib/ruby_qb101.rb', line 47

def title()
  @px.summary.title
end

#to_htmlObject



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_mdObject



51
52
53
# File 'lib/ruby_qb101.rb', line 51

def to_md()
  @questions
end

#to_promptsObject



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_tocObject



71
72
73
# File 'lib/ruby_qb101.rb', line 71

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

#to_xmlObject



75
76
77
# File 'lib/ruby_qb101.rb', line 75

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