Class: Gettc::Problem
- Inherits:
-
Object
- Object
- Gettc::Problem
- Defined in:
- lib/gettc/print.rb,
lib/gettc/problem.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#examples ⇒ Object
Returns the value of attribute examples.
-
#id ⇒ Object
Returns the value of attribute id.
-
#images ⇒ Object
Returns the value of attribute images.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#source ⇒ Object
Returns the value of attribute source.
-
#statement ⇒ Object
Returns the value of attribute statement.
-
#systests ⇒ Object
Returns the value of attribute systests.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize ⇒ Problem
constructor
A new instance of Problem.
- #to_html ⇒ Object
- #to_md ⇒ Object
Constructor Details
#initialize ⇒ Problem
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
#constraints ⇒ Object
Returns the value of attribute constraints.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def constraints @constraints end |
#definitions ⇒ Object
Returns the value of attribute definitions.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def definitions @definitions end |
#examples ⇒ Object
Returns the value of attribute examples.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def examples @examples end |
#id ⇒ Object
Returns the value of attribute id.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def id @id end |
#images ⇒ Object
Returns the value of attribute images.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def images @images end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def name @name end |
#notes ⇒ Object
Returns the value of attribute notes.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def notes @notes end |
#source ⇒ Object
Returns the value of attribute source.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def source @source end |
#statement ⇒ Object
Returns the value of attribute statement.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def statement @statement end |
#systests ⇒ Object
Returns the value of attribute systests.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def systests @systests end |
#url ⇒ Object
Returns the value of attribute url.
22 23 24 |
# File 'lib/gettc/problem.rb', line 22 def url @url end |
Instance Method Details
#to_html ⇒ Object
50 51 52 |
# File 'lib/gettc/print.rb', line 50 def to_html RDiscount.new(to_md).to_html end |
#to_md ⇒ Object
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 |