Class: Brine::ParameterTransforming::Transformer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#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

#typeObject (readonly)

Provide an identifier for this Transformer.



28
29
30
# File 'lib/brine/transforming.rb', line 28

def type
  @type
end

Instance Method Details

#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

#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