Class: FormatProblem2Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/exporter/doc/format_problem2doc.rb

Instance Method Summary collapse

Constructor Details

#initialize(problem) ⇒ FormatProblem2Doc

Returns a new instance of FormatProblem2Doc.



2
3
4
# File 'lib/asker/exporter/doc/format_problem2doc.rb', line 2

def initialize(problem)
  @problem = problem
end

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/asker/exporter/doc/format_problem2doc.rb', line 6

def call
  # attr_accessor :varnames
  # attr_accessor :cases
  out = ""
  title = "Problem: #{@problem.name}"
  out << ("-" * title.size + "\n")
  out << "#{title}\n"
  desc = replace_case_values(@problem.desc)
  out << "#{desc}\n"
  @problem.asks.each_with_index do |ask, index|
    text = replace_case_values(ask[:text])
    out << "#{index + 1}) #{text}\n"
    if ask[:answer]
      answer = replace_case_values(ask[:answer])
      out << "   #{answer}\n"
    else
      ask[:steps].each do |step|
        step = replace_case_values(step)
        out << "   #{step}\n"
      end
    end
  end
  out << "\n"
  out << "\n"
  out
end