Class: Remi::Transform::Prefix

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

Overview

Public: Transform used to prefix string values in a vector.

prefix - The string prefix. if_blank - String value to substitute if the value is blank (default: ”).

Examples:

Prefix.new('CU').to_proc.call('123') # => "CU123"

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(prefix, *args, if_blank: '', **kargs, &block) ⇒ Prefix

Returns a new instance of Prefix.



65
66
67
68
69
# File 'lib/remi/transform.rb', line 65

def initialize(prefix, *args, if_blank: '', **kargs, &block)
  super
  @prefix   = prefix
  @if_blank = if_blank
end

Instance Method Details

#transform(value) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/remi/transform.rb', line 71

def transform(value)
  if value.blank?
    @if_blank
  else
    "#{@prefix}#{value}"
  end
end