Class: Stockboy::Translations::Integer

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

Overview

Translate string values to Integer

Job template DSL

Registered as :integer. Use with:

attributes do
  children as: :integer
end

Examples:

num = Stockboy::Translator::Integer.new

record.children = "2"
num.translate(record, :children) # => 2

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) ⇒ Integer

Returns:



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

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

  value.to_i
end