Class: AocCli::Helpers::TableGenerator

Inherits:
Object
  • Object
show all
Includes:
Kangaru::Validatable
Defined in:
lib/aoc_cli/helpers/table_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows:, gap: 2, indent: 0) ⇒ TableGenerator

Returns a new instance of TableGenerator.



10
11
12
13
14
# File 'lib/aoc_cli/helpers/table_generator.rb', line 10

def initialize(rows:, gap: 2, indent: 0)
  @rows = rows
  @gap = gap
  @indent = indent
end

Instance Attribute Details

#gapObject (readonly)

Returns the value of attribute gap.



6
7
8
# File 'lib/aoc_cli/helpers/table_generator.rb', line 6

def gap
  @gap
end

#indentObject (readonly)

Returns the value of attribute indent.



6
7
8
# File 'lib/aoc_cli/helpers/table_generator.rb', line 6

def indent
  @indent
end

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/aoc_cli/helpers/table_generator.rb', line 6

def rows
  @rows
end

Instance Method Details

#generate!Object



29
30
31
32
33
34
35
# File 'lib/aoc_cli/helpers/table_generator.rb', line 29

def generate!
  validate!

  rows.map do |row|
    [space(indent), format_row!(row).strip, "\n"].join
  end.join
end

#validateObject

TODO: Use validates via method for checking row length once supported.



17
18
19
20
# File 'lib/aoc_cli/helpers/table_generator.rb', line 17

def validate
  super
  validate_rows_are_same_length! if errors.empty?
end

#validate!Object

TODO: Remove once validate! merged upstream.



23
24
25
26
27
# File 'lib/aoc_cli/helpers/table_generator.rb', line 23

def validate!
  validate

  raise errors.map(&:full_message).join("\n") unless errors.empty?
end