Class: Scraped::ResponseDecorator
- Inherits:
-
Object
- Object
- Scraped::ResponseDecorator
- Defined in:
- lib/scraped/response_decorator.rb
Instance Method Summary collapse
-
#initialize(response:, decorators:) ⇒ ResponseDecorator
constructor
A new instance of ResponseDecorator.
- #response ⇒ Object
Constructor Details
#initialize(response:, decorators:) ⇒ ResponseDecorator
Returns a new instance of ResponseDecorator.
3 4 5 6 |
# File 'lib/scraped/response_decorator.rb', line 3 def initialize(response:, decorators:) @original_response = response @decorators = decorators.to_a end |
Instance Method Details
#response ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/scraped/response_decorator.rb', line 8 def response decorators.reduce(original_response) do |r, decorator_config| unless decorator_config.respond_to?(:[]) decorator_config = { decorator: decorator_config } end decorator_class = decorator_config[:decorator] decorator_class.new(response: r, config: decorator_config) .decorated_response end end |