Class: Eskimo::ASCII::Gutter
- 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
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
Instance Method Summary collapse
-
#initialize(char:, spacing: 0, &children) ⇒ Gutter
constructor
A new instance of Gutter.
- #render ⇒ Object
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
#char ⇒ Object (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 |
#spacing ⇒ Object (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
#render ⇒ Object
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 |