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_args, #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.



207
208
209
210
# File 'lib/remi/transform.rb', line 207

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

Instance Method Details

#transform(value) ⇒ Object



212
213
214
# File 'lib/remi/transform.rb', line 212

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