Class: RSpock::Tasks::TruthTable
- Inherits:
-
Object
- Object
- RSpock::Tasks::TruthTable
- Defined in:
- lib/rspock/tasks/truth_table.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#table_data ⇒ Object
readonly
Returns the value of attribute table_data.
Instance Method Summary collapse
-
#initialize(header, values_mapping) ⇒ TruthTable
constructor
Constructs a new TruthTable.
-
#table ⇒ Array<Array<String>>
(also: #to_h)
Retrieves the full table with header.
-
#to_s ⇒ String
Retrieves the table as a formatted string.
Constructor Details
#initialize(header, values_mapping) ⇒ TruthTable
Constructs a new TruthTable.
and value being an Array of possible values.
10 11 12 13 |
# File 'lib/rspock/tasks/truth_table.rb', line 10 def initialize(header, values_mapping) @header = header.dup.freeze @table_data = generate(@header.reverse, values_mapping, 0, []).freeze end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
15 16 17 |
# File 'lib/rspock/tasks/truth_table.rb', line 15 def header @header end |
#table_data ⇒ Object (readonly)
Returns the value of attribute table_data.
15 16 17 |
# File 'lib/rspock/tasks/truth_table.rb', line 15 def table_data @table_data end |
Instance Method Details
#table ⇒ Array<Array<String>> Also known as: to_h
Retrieves the full table with header.
20 21 22 23 24 25 26 |
# File 'lib/rspock/tasks/truth_table.rb', line 20 def table @table ||= begin data = table_data.empty? ? [] : table_data.dup data.unshift(header) unless header.empty? data end.freeze end |
#to_s ⇒ String
Retrieves the table as a formatted string.
33 34 35 |
# File 'lib/rspock/tasks/truth_table.rb', line 33 def to_s @to_s ||= format(to_h) end |