Class: Brine::ParameterTransforming::Transformer
- Inherits:
-
Object
- Object
- Brine::ParameterTransforming::Transformer
- Defined in:
- lib/brine/transforming.rb
Overview
Transform supported input.
This implementation is designed around instances being defined with patterns which define whether they should handle provided input, and procs which should do the transformation (when the patterns match).
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Provide an identifier for this Transformer.
Instance Method Summary collapse
-
#can_handle?(input) ⇒ Boolean
Indicate whether this instance should attempt to transform the input.
-
#initialize(type, pattern, &xfunc) ⇒ Transformer
constructor
Construct a new Transformer instance configured as specified.
-
#transform(input) ⇒ Object
Transform the provided input.
Constructor Details
#initialize(type, pattern, &xfunc) ⇒ Transformer
Construct a new Transformer instance configured as specified.
40 41 42 43 44 |
# File 'lib/brine/transforming.rb', line 40 def initialize(type, pattern, &xfunc) @type = type @pattern = pattern @xfunc = xfunc end |
Instance Attribute Details
#type ⇒ Object (readonly)
Provide an identifier for this Transformer.
29 30 31 |
# File 'lib/brine/transforming.rb', line 29 def type @type end |
Instance Method Details
#can_handle?(input) ⇒ Boolean
Indicate whether this instance should attempt to transform the input.
52 53 54 |
# File 'lib/brine/transforming.rb', line 52 def can_handle?(input) input =~ @pattern end |
#transform(input) ⇒ Object
Transform the provided input.
62 63 64 65 |
# File 'lib/brine/transforming.rb', line 62 def transform(input) STDERR.puts("Handling #{input} as #{@type}") if ENV['BRINE_LOG_TRANSFORMS'] @xfunc.call(input) end |