Class: Eskimo::ASCII::Squeeze
- Inherits:
-
Object
- Object
- Eskimo::ASCII::Squeeze
- Defined in:
- gems/eskimo-ascii/lib/eskimo/ascii/components/squeeze.rb
Overview
Instance Method Summary collapse
-
#initialize(children) ⇒ Squeeze
constructor
A new instance of Squeeze.
- #render(**props) ⇒ Object
Constructor Details
#initialize(children) ⇒ Squeeze
Returns a new instance of Squeeze
24 25 26 27 28 29 30 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/squeeze.rb', line 24 def initialize(children) if !children.is_a?(Array) || block_given? raise ArgumentError.new("Squeeze works only with an Array of components") end @children = children end |
Instance Method Details
#render(**props) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/squeeze.rb', line 32 def render(**props) rendered = @children.map(&props[:render]) without_blanks = rendered.reject(&:empty?) without_blanks.reject.with_index do |element, index| element == "\n" && without_blanks[index+1] == "\n" end end |