Class: Stockboy::Translations::String

Inherits:
Stockboy::Translator show all
Defined in:
lib/stockboy/translations/string.rb

Overview

Cleans string values by stripping surrounding whitespace

Job template DSL

Registered as :string. Use with:

attributes do
  name as: :string
end

Examples:

str = Stockboy::Translator::String.new

record.name = "Arthur  "
str.translate(record, :name) # => "Arthur"

Instance Attribute Summary

Attributes inherited from Stockboy::Translator

#field_key

Instance Method Summary collapse

Methods inherited from Stockboy::Translator

#call, #initialize, #inspect

Constructor Details

This class inherits a constructor from Stockboy::Translator

Instance Method Details

#translate(context) ⇒ String

Returns:



25
26
27
28
29
30
# File 'lib/stockboy/translations/string.rb', line 25

def translate(context)
  value = field_value(context, field_key)
  return "" if value.nil?

  value.to_s.strip
end