Class: Remi::Transform
- Inherits:
-
Object
- Object
- Remi::Transform
- Defined in:
- lib/remi/transform.rb
Direct Known Subclasses
Concatenate, Constant, DataFrameSieve, DateDiff, EnforceType, FormatDate, IfBlank, Lookup, Nvl, ParseDate, Partitioner, Postfix, Prefix, Replace, Truncate, Truthy, ValidateEmail
Defined Under Namespace
Classes: Concatenate, Constant, DataFrameSieve, DateDiff, EnforceType, FormatDate, IfBlank, Lookup, Nvl, ParseDate, Partitioner, Postfix, Prefix, Replace, Truncate, Truthy, ValidateEmail
Instance Attribute Summary collapse
-
#multi_args ⇒ Object
readonly
Public: Set to true if the transform expects multiple arguments (default: false).
-
#source_metadata ⇒ Object
Public: Accessor for source metadata.
-
#target_metadata ⇒ Object
Public: Accessor for target metadata.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Public: Allows one to call the proc defined by the transform so that Remi::Transform instances can be used interchangeably with normal lambdas.
-
#initialize(*args, source_metadata: {}, target_metadata: {}, **kargs, &block) ⇒ Transform
constructor
Public: Initializes the static arguments of a transform.
-
#to_proc ⇒ Object
Public: Returns the transform as a lambda.
-
#transform(value) ⇒ Object
Public: Defines the operation of this transform class.
Constructor Details
#initialize(*args, source_metadata: {}, target_metadata: {}, **kargs, &block) ⇒ Transform
Public: Initializes the static arguments of a transform.
source_metadata - Metadata for the transform source. target_metadata - Metadata for the transform target.
8 9 10 11 12 |
# File 'lib/remi/transform.rb', line 8 def initialize(*args, source_metadata: {}, target_metadata: {}, **kargs, &block) @source_metadata = @target_metadata = @multi_args = false end |
Instance Attribute Details
#multi_args ⇒ Object (readonly)
Public: Set to true if the transform expects multiple arguments (default: false)
21 22 23 |
# File 'lib/remi/transform.rb', line 21 def multi_args @multi_args end |
#source_metadata ⇒ Object
Public: Accessor for source metadata
15 16 17 |
# File 'lib/remi/transform.rb', line 15 def @source_metadata end |
#target_metadata ⇒ Object
Public: Accessor for target metadata
18 19 20 |
# File 'lib/remi/transform.rb', line 18 def @target_metadata end |
Instance Method Details
#call(*args) ⇒ Object
Public: Allows one to call the proc defined by the transform so that Remi::Transform instances can be used interchangeably with normal lambdas.
values - The values to be transformed.
Returns the transformed value.
38 39 40 41 42 43 44 |
# File 'lib/remi/transform.rb', line 38 def call(*args) if to_proc.arity == 0 to_proc.call else to_proc.call(*args) end end |
#to_proc ⇒ Object
Public: Returns the transform as a lambda.
47 48 49 |
# File 'lib/remi/transform.rb', line 47 def to_proc @to_proc ||= method(:transform).to_proc end |
#transform(value) ⇒ Object
Public: Defines the operation of this transform class.
value - The value to be transformed
Returns the transformed value.
28 29 30 |
# File 'lib/remi/transform.rb', line 28 def transform(value) raise NoMethodError, "#{__method__} not defined for #{self.class.name}" end |