Class: Eskimo::ASCII::Gutter

Inherits:
Component show all
Defined in:
gems/eskimo-ascii/lib/eskimo/ascii/components/gutter.rb

Overview

Prepend each line with a character or symbol.

Gutter.new(char: '| ') do
  [ "Hello", "\n", "World!" ]
end
# => "| Hello"
#    "| World!"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char:, spacing: 0, &children) ⇒ Gutter

Returns a new instance of Gutter



14
15
16
17
18
19
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/gutter.rb', line 14

def initialize(char:, spacing: 0, &children)
  @char = char
  @spacing = spacing

  super
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char



12
13
14
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/gutter.rb', line 12

def char
  @char
end

#spacingObject (readonly)

Returns the value of attribute spacing



12
13
14
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/gutter.rb', line 12

def spacing
  @spacing
end

Instance Method Details

#renderObject



21
22
23
24
25
26
27
28
29
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/gutter.rb', line 21

def render(**)
  spacer = Array.new(spacing, char)

  [
    *spacer,
    super.lines.map { |s| s.prepend(char) }.join,
    *spacer
  ].join("\n")
end