Class: Leftovers::ProcessorBuilders::Each

Inherits:
Object
  • Object
show all
Defined in:
lib/leftovers/processor_builders/each.rb

Direct Known Subclasses

EachForDefinitionSet

Class Method Summary collapse

Class Method Details

.build(processors) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/leftovers/processor_builders/each.rb', line 15

def build(processors)
  processors = compact(processors)

  case processors.length
  # :nocov:
  when 0 then raise UnexpectedCase, "Unhandled value #{processors.inspect}"
  # :nocov:
  when 1 then processors.first
  else processor_class.new(processors)
  end
end

.each_or_self(value, &block) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/leftovers/processor_builders/each.rb', line 7

def each_or_self(value, &block)
  case value
  when nil then nil
  when ::Array then build(value.map(&block))
  else build([yield(value)])
  end
end