class Stockboy::Translations::DefaultEmptyString

Translate missing values to empty string

This is a useful fallback for translation errors.

Job template DSL

Registered as :or_empty. Use with:

attributes do
  product_code as: [->(r){raise "Invalid"}, :or_empty]
end

@example

str = Stockboy::Translator::DefaultEmptyString.new

record.product_code = "ITEM"
str.translate(record, :product_code) # => "ITEM"

record.product_code = nil
str.translate(record, :product_code) # => ""

Public Instance Methods

translate(context) click to toggle source

@return [String]

# File lib/stockboy/translations/default_empty_string.rb, line 30
def translate(context)
  value = field_value(context, field_key)
  return "" if (value).blank?

  return value
end