Class: Spirit::Render::Table
- Defined in:
- lib/spirit/render/templates/table.rb
Overview
Renders table problems marked up in YAML as HTML.
The grid should be given as a 2-dimensional array that represents the table to be filled in. “?” is a special token used in the grid to indicate cells that require student input.
The answer should also be given as a 2-dimensional array. However, a dummy token may be used in cells that do not require student input to cut redundancy. In the example below, the “-” token is used.
Constant Summary collapse
- HEADINGS =
Optional headings key.
'headings'
- GRID =
Required grid key.
'grid'
- FILL_ME_IN =
Special token indicating that the cell should be filled in.
'?'
Constants inherited from Problem
Problem::ANSWER, Problem::FORMAT, Problem::ID, Problem::KEYS, Problem::QUESTION
Instance Attribute Summary
Attributes inherited from Problem
Class Method Summary collapse
-
.input?(cell) ⇒ Boolean
True iff the given cell is an input cell.
Instance Method Summary collapse
-
#answer ⇒ Hash
Gets the expected answer, in www-form-urlencoded format.
-
#initialize(yaml, digest) ⇒ Table
constructor
Ensures that the
headings
key exists. -
#valid? ⇒ Boolean
Checks if the given yaml contains a valid table.
Methods inherited from Problem
accessor, get_instance, parse, #render
Methods inherited from Template
Constructor Details
Class Method Details
.input?(cell) ⇒ Boolean
Returns true iff the given cell is an input cell.
61 62 63 |
# File 'lib/spirit/render/templates/table.rb', line 61 def self.input?(cell) cell == FILL_ME_IN end |
Instance Method Details
#answer ⇒ Hash
Gets the expected answer, in www-form-urlencoded format.
55 56 57 58 |
# File 'lib/spirit/render/templates/table.rb', line 55 def answer return @answer unless @answer.nil? @answer = encode_answer end |
#valid? ⇒ Boolean
Checks if the given yaml contains a valid table.
47 48 49 50 51 |
# File 'lib/spirit/render/templates/table.rb', line 47 def valid? super and valid_grid? and valid_answer? end |