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)
- #to_html ⇒ Object
- #to_md ⇒ Object
- #to_toc ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(questions_file = nil) ⇒ Ruby_Qb101
Returns a new instance of Ruby_Qb101.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_qb101.rb', line 13 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
24 25 26 27 28 29 |
# File 'lib/ruby_qb101.rb', line 24 def question(id) found = @px.find_by_id(id.to_s) found.x if found end |
#to_html ⇒ Object
37 38 39 |
# File 'lib/ruby_qb101.rb', line 37 def to_html() Kramdown::Document.new(@questions).to_html end |
#to_md ⇒ Object
33 34 35 |
# File 'lib/ruby_qb101.rb', line 33 def to_md() @questions end |
#to_toc ⇒ Object
41 42 43 |
# File 'lib/ruby_qb101.rb', line 41 def to_toc() Yatoc.new(self.to_html(), min_sections: 1) end |
#to_xml ⇒ Object
45 46 47 |
# File 'lib/ruby_qb101.rb', line 45 def to_xml() @px.to_xml(pretty: true) end |