Class: RSpock::Tasks::TruthTable

Inherits:
Object
  • Object
show all
Defined in:
lib/rspock/tasks/truth_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, values_mapping) ⇒ TruthTable

Constructs a new TruthTable.

and value being an Array of possible values.

Parameters:

  • header (Array<String>)

    The column names, in a left to right order.

  • values_mapping (Hash<String, Array<String>>)

    A hash of the possible values with key being a column name



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

#headerObject (readonly)

Returns the value of attribute header.



15
16
17
# File 'lib/rspock/tasks/truth_table.rb', line 15

def header
  @header
end

#table_dataObject (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

#tableArray<Array<String>> Also known as: to_h

Retrieves the full table with header.

Returns:

  • (Array<Array<String>>)

    The table’s lines.



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_sString

Retrieves the table as a formatted string.

Returns:

  • (String)

    The formatted table.



33
34
35
# File 'lib/rspock/tasks/truth_table.rb', line 33

def to_s
  @to_s ||= format(to_h)
end