Class: Remi::Transform::IfBlank

Inherits:
Remi::Transform show all
Defined in:
lib/remi/transform.rb

Overview

Public: Used to replace blank values.

replace_with - Use this if the source value is blank (default: ”).

Examples:

IfBlank.new('MISSING VALUE').to_proc.call('alpha') # => "alpha"
IfBlank.new('MISSING VALUE').to_proc.call('') # => "MISSING VALUE"

Instance Attribute Summary

Attributes inherited from Remi::Transform

#multi_arg, #source_metadata, #target_metadata

Instance Method Summary collapse

Methods inherited from Remi::Transform

#call, #to_proc

Constructor Details

#initialize(replace_with = '', *args, **kargs, &block) ⇒ IfBlank

Returns a new instance of IfBlank.



205
206
207
208
# File 'lib/remi/transform.rb', line 205

def initialize(replace_with='', *args, **kargs, &block)
  super
  @replace_with = replace_with
end

Instance Method Details

#transform(value) ⇒ Object



210
211
212
# File 'lib/remi/transform.rb', line 210

def transform(value)
  value.blank? ? @replace_with : value
end