Class: BlankAttributes::TypeHandler
- Inherits:
-
Object
- Object
- BlankAttributes::TypeHandler
- Defined in:
- lib/blank_attributes/type_handler.rb
Constant Summary collapse
- STRING_TYPES =
[:string, :text]
- ARRAY_TYPES =
[:array]
Instance Method Summary collapse
-
#initialize(object) ⇒ TypeHandler
constructor
A new instance of TypeHandler.
- #normalize(attr_name) ⇒ Object
Constructor Details
#initialize(object) ⇒ TypeHandler
Returns a new instance of TypeHandler.
9 10 11 |
# File 'lib/blank_attributes/type_handler.rb', line 9 def initialize(object) @object = object end |
Instance Method Details
#normalize(attr_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/blank_attributes/type_handler.rb', line 13 def normalize(attr_name) income_value = value(attr_name) attr_type = @object.class.columns_hash[attr_name.to_s] if attr_type.respond_to?(:array) && attr_type.array == true normalize_array(income_value) elsif STRING_TYPES.include?(attr_type.type) normalize_string(income_value) else income_value end rescue income_value end |