Class: Remap::Selector::All

Inherits:
Concrete
  • Object
show all
Defined in:
lib/remap/selector/all.rb

Overview

Selects all elements from a state

Examples:

Select all keys from array hash

state = Remap::State.call([{a: "A1"}, {a: "A2"}])
all = Remap::Selector::All.new
result = all.call(state) do |other_state|
  value = other_state.fetch(:value).class
  other_state.merge(value: value)
end
result.fetch(:value) # => [Hash, Hash]

Instance Method Summary collapse

Instance Method Details

#call(state) {|| ... } ⇒ State<U>

Iterates over state and passes each value to block

Parameters:

  • state (State<Enumerable<T>>)

Yield Parameters:

Yield Returns:

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/remap/selector/all.rb', line 26

def call(state, &block)
  unless block
    raise ArgumentError, "All selector requires an iteration block"
  end

  value = state.fetch(:value) do
    return state
  end

  unless value.is_a?(Enumerable)
    state.fatal!("Not an enumerator")
  end

  state.map(&block)
end