Class: Porridge::Extractor
- Inherits:
-
Object
- Object
- Porridge::Extractor
- Defined in:
- lib/porridge/extractor.rb
Overview
Extractor is the nominal base class for all porridge value extractors.
A (value) extractor is an object that is capable of retrieving a value from an object, given a set of “options”, which may be application-specific. You are encouraged, but not required, to have your extractors derive from this class. Currently, any object that implements a #call
method is a valid extractor.
Direct Known Subclasses
Class Method Summary collapse
-
.ensure_valid!(*objects) ⇒ Boolean
Ensures that all the provided objects are valid extractors, raising InvalidExtractorError if not.
-
.valid?(object) ⇒ Boolean
Determines whether the given object is a valid porridge extractor.
Instance Method Summary collapse
-
#call(object, options) ⇒ Object
Should extract a value from the given object with the given options.
Class Method Details
.ensure_valid!(*objects) ⇒ Boolean
Ensures that all the provided objects are valid extractors, raising InvalidExtractorError if not.
22 23 24 25 |
# File 'lib/porridge/extractor.rb', line 22 def self.ensure_valid!(*objects) objects.each { |object| raise InvalidExtractorError unless valid?(object) } true end |
.valid?(object) ⇒ Boolean
Determines whether the given object is a valid porridge extractor. Currently, any object that responds to the #call
method is valid.
14 15 16 |
# File 'lib/porridge/extractor.rb', line 14 def self.valid?(object) object.respond_to? :call end |
Instance Method Details
#call(object, options) ⇒ Object
Should extract a value from the given object with the given options. Subclasses should override this method.
31 |
# File 'lib/porridge/extractor.rb', line 31 def call(object, ); end |