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
permalink #initialize(type, pattern, &xfunc) ⇒ Transformer
Construct a new Transformer instance configured as specified.
39 40 41 42 43 |
# File 'lib/brine/transforming.rb', line 39 def initialize(type, pattern, &xfunc) @type = type @pattern = pattern @xfunc = xfunc end |
Instance Attribute Details
permalink #type ⇒ Object (readonly)
Provide an identifier for this Transformer.
28 29 30 |
# File 'lib/brine/transforming.rb', line 28 def type @type end |
Instance Method Details
permalink #can_handle?(input) ⇒ Boolean
Indicate whether this instance should attempt to transform the input.
51 52 53 |
# File 'lib/brine/transforming.rb', line 51 def can_handle?(input) input =~ @pattern end |
permalink #transform(input) ⇒ Object
Transform the provided input.
61 62 63 64 |
# File 'lib/brine/transforming.rb', line 61 def transform(input) STDERR.puts("Handling #{input} as #{@type}") if ENV['BRINE_LOG_TRANSFORMS'] @xfunc.call(input) end |