Class: Polites::CodeGrouper

Inherits:
Object
  • Object
show all
Defined in:
lib/polites/code_grouper.rb

Overview

Take a list of items and collapse a collection of subsequent code blocks into a single one separated by newlines.

Instance Method Summary collapse

Instance Method Details

#call(items) ⇒ Array<Polites::Node>

Parameters:

Returns:



9
10
11
12
13
14
15
# File 'lib/polites/code_grouper.rb', line 9

def call(items)
  items
    .chunk { |i| i.is_a?(Block::CodeBlock) }.to_a
    .inject([]) do |acc, (k, contents)|
    acc + (k ? [combine(contents)] : contents)
  end
end