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.



32
33
34
# File 'lib/salestation/web/extractors.rb', line 32

def initialize(extractors)
  @extractors = extractors
end

Instance Method Details

#call(rack_request) ⇒ Object



46
47
48
49
50
# File 'lib/salestation/web/extractors.rb', line 46

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

#coerce(rules) ⇒ Object



56
57
58
# File 'lib/salestation/web/extractors.rb', line 56

def coerce(rules)
  InputCoercer.new(self, rules)
end

#compose_seq(fns, input) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/salestation/web/extractors.rb', line 36

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



52
53
54
# File 'lib/salestation/web/extractors.rb', line 52

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