class DbToFile::ValuesNormalizer::ObjectToHash
Public Class Methods
new(object)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 4 def initialize(object) @object = object end
Public Instance Methods
normalize()
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 8 def normalize @hash = {} @object.attributes.each do |field, value| @current_field = field @hash[field] = normalize_field_value(value) end @hash end
Private Instance Methods
add_trailing_newline(string)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 41 def add_trailing_newline(string) (string[-1] == "\n") ? string : "#{string}\n" end
convert_integer_to_string(integer)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 37 def convert_integer_to_string(integer) "#{integer}" end
convert_nil_value(value)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 33 def convert_nil_value(value) (value.nil?) ? '<NULL>' : value end
convert_yaml(value)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 25 def convert_yaml(value) (!value.nil? && serialized_attribute?(@current_field)) ? value.to_yaml : value end
normalize_field_value(value)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 18 def normalize_field_value(value) value = convert_yaml(value) value = convert_nil_value(value) value = convert_integer_to_string(value) value = add_trailing_newline(value) end
serialized_attribute?(field)
click to toggle source
# File lib/db_to_file/values_normalizer/object_to_hash.rb, line 29 def serialized_attribute?(field) @object.class.serialized_attributes.keys.include?(field.to_s) end