Class: AocCli::Helpers::TableGenerator
- Inherits:
-
Object
- Object
- AocCli::Helpers::TableGenerator
- Includes:
- Kangaru::Validatable
- Defined in:
- lib/aoc_cli/helpers/table_generator.rb
Instance Attribute Summary collapse
-
#gap ⇒ Object
readonly
Returns the value of attribute gap.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #generate! ⇒ Object
-
#initialize(rows:, gap: 2, indent: 0) ⇒ TableGenerator
constructor
A new instance of TableGenerator.
-
#validate ⇒ Object
TODO: Use validates via method for checking row length once supported.
-
#validate! ⇒ Object
TODO: Remove once validate! merged upstream.
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
#gap ⇒ Object (readonly)
Returns the value of attribute gap.
6 7 8 |
# File 'lib/aoc_cli/helpers/table_generator.rb', line 6 def gap @gap end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
6 7 8 |
# File 'lib/aoc_cli/helpers/table_generator.rb', line 6 def indent @indent end |
#rows ⇒ Object (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 |
#validate ⇒ Object
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 |