Class: Gettc::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/gettc/print.rb,
lib/gettc/problem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProblem

Returns a new instance of Problem.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gettc/problem.rb', line 25

def initialize
  @id = 0
  @name = ""
  @url = ""
  @source = ""
  @statement = ""
  @definitions = {}
  @notes = []
  @constraints = []
  @examples = []
  @systests = []
  @images = []
end

Instance Attribute Details

#constraintsObject

Returns the value of attribute constraints.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def constraints
  @constraints
end

#definitionsObject

Returns the value of attribute definitions.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def definitions
  @definitions
end

#examplesObject

Returns the value of attribute examples.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def examples
  @examples
end

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def id
  @id
end

#imagesObject

Returns the value of attribute images.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def images
  @images
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def name
  @name
end

#notesObject

Returns the value of attribute notes.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def notes
  @notes
end

#sourceObject

Returns the value of attribute source.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def source
  @source
end

#statementObject

Returns the value of attribute statement.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def statement
  @statement
end

#systestsObject

Returns the value of attribute systests.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def systests
  @systests
end

#urlObject

Returns the value of attribute url.



22
23
24
# File 'lib/gettc/problem.rb', line 22

def url
  @url
end

Instance Method Details

#to_htmlObject



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

def to_html
  RDiscount.new(to_md).to_html
end

#to_mdObject



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gettc/print.rb', line 6

def to_md
  out  = "# [#{@name}](#{@url})\n"
  out << "*#{@source}*\n\n"

  out << "## Statement\n"
  out << @statement << "\n\n"

  unless @definitions.empty?
    out << "## Definitions\n"
    @definitions.each { |k, v| out << "- *#{k}*: `#{v}`\n" }
    out << "\n"
  end

  unless @notes.empty?
    out << "## Notes\n"
    @notes.each { |note| out << "- #{note}\n" }
    out << "\n"
  end

  unless @constraints.empty?
    out << "## Constraints\n"
    @constraints.each { |constraint| out << "- #{constraint}\n" }
    out << "\n"
  end

  unless @examples.empty?
    out << "## Examples\n"

    @examples.each_index do |i|
      example = @examples[i]
      out << "### Example #{i + 1}\n"
      out << "#### Input\n<c>"
      out << example.input.gsub("\n", "<br />")
      out << "</c>\n"
      out << "#### Output\n<c>"
      out << example.output.gsub("\n", "<br />")
      out << "</c>\n"
      out << "#### Reason\n#{example.reason}\n\n" unless example.reason.empty?
    end
  end

  out
end