class Rseed::Converter
Attributes
converter_attributes[RW]
error[R]
logger[W]
options[W]
Public Class Methods
attribute(name, options)
click to toggle source
Used to define an attribute when creating a converter.
# File lib/rseed/converter.rb, line 31 def self.attribute name, options @converter_attributes ||= [] converter_attributes << Attribute.new(name, options) end
mandatory_attributes()
click to toggle source
# File lib/rseed/converter.rb, line 43 def self.mandatory_attributes converter_attributes.reject { |a| a.options[:optional] } end
name()
click to toggle source
# File lib/rseed/converter.rb, line 11 def self.name class_name = self.to_s m = /^(?<name>.*)Converter$/.match(class_name) m ? m[:name] : class_name end
Public Instance Methods
after_deserialize()
click to toggle source
# File lib/rseed/converter.rb, line 40 def after_deserialize end
before_deserialize()
click to toggle source
# File lib/rseed/converter.rb, line 36 def before_deserialize true end
deserialize(values)
click to toggle source
Dummy convert function
# File lib/rseed/converter.rb, line 59 def deserialize values logger.debug values end
deserialize_raw(values)
click to toggle source
Takes the raw values coming out of an adapter and converts them based on the attribute definitions in the converter.
# File lib/rseed/converter.rb, line 49 def deserialize_raw values converted_values = HashWithIndifferentAccess.new self.class.converter_attributes.each do |attribute| converted_values[attribute.name] = attribute.deserialize(values, converter: self) end deserialize converted_values end
fail_with_error(e)
click to toggle source
# File lib/rseed/converter.rb, line 72 def fail_with_error e @error = e false end
logger()
click to toggle source
# File lib/rseed/converter.rb, line 21 def logger @logger.nil? ? Rseed.logger : @logger end
name()
click to toggle source
# File lib/rseed/converter.rb, line 17 def name self.class.name end
options()
click to toggle source
# File lib/rseed/converter.rb, line 25 def options @options ||= {} @options end
remove_blank_from(values)
click to toggle source
# File lib/rseed/converter.rb, line 68 def remove_blank_from values values.delete_if { |k, v| v.to_s.blank? } end
remove_nil_from(values)
click to toggle source
Helpers for converters
# File lib/rseed/converter.rb, line 64 def remove_nil_from values values.delete_if { |k, v| v.nil? } end