Class: Porridge::SendExtractor
- Defined in:
- lib/porridge/send_extractor.rb
Overview
SendExtractor is an extractor that retrieves a value from an object by simply calling a predefined method on it.
Instance Attribute Summary collapse
-
#method_name ⇒ String
readonly
private
The name of the method to call when extracting the value.
Instance Method Summary collapse
-
#call(object, _options) ⇒ Object
Extracts the value from the given object by sending the method name (#method_name) to it.
-
#initialize(method_name) ⇒ SendExtractor
constructor
Creates a new instance of SendExtractor with the given method name.
Methods inherited from Extractor
Constructor Details
#initialize(method_name) ⇒ SendExtractor
Creates a new instance of Porridge::SendExtractor with the given method name.
8 9 10 11 |
# File 'lib/porridge/send_extractor.rb', line 8 def initialize(method_name) @method_name = method_name.to_s super() end |
Instance Attribute Details
#method_name ⇒ String (readonly, private)
The name of the method to call when extracting the value.
25 26 27 |
# File 'lib/porridge/send_extractor.rb', line 25 def method_name @method_name end |
Instance Method Details
#call(object, _options) ⇒ Object
Extracts the value from the given object by sending the method name (#method_name) to it.
17 18 19 |
# File 'lib/porridge/send_extractor.rb', line 17 def call(object, ) object.respond_to?(method_name) ? object.send(method_name) : nil end |