Class: Courgette::Chain
- Inherits:
-
Object
- Object
- Courgette::Chain
- Defined in:
- lib/courgette/chain.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply(ip, hash) ⇒ Object
-
#initialize(fetcher, processors) ⇒ Chain
constructor
A new instance of Chain.
- #responsible_of(vendor) ⇒ Object
Constructor Details
#initialize(fetcher, processors) ⇒ Chain
Returns a new instance of Chain.
3 4 5 6 |
# File 'lib/courgette/chain.rb', line 3 def initialize(fetcher, processors) @fetcher = fetcher @processors = processors end |
Class Method Details
.all ⇒ Object
21 22 23 24 25 |
# File 'lib/courgette/chain.rb', line 21 def self.all [ Chain.of(Fetchers::CommutateursFetcher, Processors::DefaultProcessor, Processors::CiscoProcessor) ] end |
.of(fetcher, *processors) ⇒ Object
8 9 10 |
# File 'lib/courgette/chain.rb', line 8 def self.of(fetcher, *processors) new(fetcher, processors) end |
Instance Method Details
#apply(ip, hash) ⇒ Object
12 13 14 15 |
# File 'lib/courgette/chain.rb', line 12 def apply(ip, hash) raw = @fetcher.new(ip, hash).fetch @processors.map(&:new).inject(raw) { |acc, p| acc = p.process(acc) } end |
#responsible_of(vendor) ⇒ Object
17 18 19 |
# File 'lib/courgette/chain.rb', line 17 def responsible_of(vendor) @fetcher.responsible_of(vendor) end |