class DbToFile::ValuesNormalizer::ValueIntoObject
Public Class Methods
new(object)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 4 def initialize(object) @object = object end
Public Instance Methods
normalize(fieldname, value)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 8 def normalize(fieldname, value) if @object.respond_to?(fieldname.to_sym) normalized_value = normalize_field_value(fieldname, value) @object.send("#{fieldname}=", normalized_value) end end
Private Instance Methods
convert_nil_value(value)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 27 def convert_nil_value(value) (value == '<NULL>') ? nil : value end
convert_yaml(value)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 31 def convert_yaml(value) (!value.nil? && serialized_attribute?(@current_field)) ? YAML.load(value) : value end
normalize_field_value(fieldname, value)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 16 def normalize_field_value(fieldname, value) @current_field = fieldname value = strip_trailing_newline(value) value = convert_nil_value(value) value = convert_yaml(value) end
serialized_attribute?(field)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 35 def serialized_attribute?(field) @object.class.serialized_attributes.keys.include?(field.to_s) end
strip_trailing_newline(text)
click to toggle source
# File lib/db_to_file/values_normalizer/value_into_object.rb, line 23 def strip_trailing_newline(text) (text[-1] == "\n") ? text[0..-2] : text end