Class: Salestation::Web::Extractors::CombinedInputExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/salestation/web/extractors.rb

Instance Method Summary collapse

Constructor Details

#initialize(extractors) ⇒ CombinedInputExtractor

Returns a new instance of CombinedInputExtractor.



21
22
23
# File 'lib/salestation/web/extractors.rb', line 21

def initialize(extractors)
  @extractors = extractors
end

Instance Method Details

#call(rack_request) ⇒ Object



35
36
37
38
39
# File 'lib/salestation/web/extractors.rb', line 35

def call(rack_request)
  compose_seq(@extractors, rack_request) do |previous_input, new_input|
    previous_input.merge(new_input)
  end
end

#compose_seq(fns, input) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/salestation/web/extractors.rb', line 25

def compose_seq(fns, input)
  fns.reduce(Deterministic::Result::Success({})) do |result, fn|
    result.map do |previous_value|
      fn.call(input).map do |new_value|
        Deterministic::Result::Success(yield(previous_value, new_value))
      end
    end
  end
end

#merge(other_extractor) ⇒ Object



41
42
43
# File 'lib/salestation/web/extractors.rb', line 41

def merge(other_extractor)
  CombinedInputExtractor.new(@extractors + [other_extractor])
end