class Relevium::Attribute
Constants
- DATE_TYPES
- TRUE_VALUES
Attributes
attribute_name[R]
remove_from_hash[R]
type[R]
Public Class Methods
new(attribute_name, type = nil, remove_from_hash = false)
click to toggle source
# File lib/relevium/form.rb, line 113 def initialize(attribute_name, type = nil, remove_from_hash = false) @attribute_name = attribute_name @type = type @remove_from_hash = remove_from_hash end
Public Instance Methods
cast_value_to_type(value)
click to toggle source
# File lib/relevium/form.rb, line 129 def cast_value_to_type(value) return TRUE_VALUES.include?(value) if type == ::Relevium::Form::Boolean return method(type.to_s).call(value) unless DATE_TYPES.include?(type) value.send("to_#{type.to_s.underscore}") end
name_to_instance_variable()
click to toggle source
# File lib/relevium/form.rb, line 136 def name_to_instance_variable "@#{attribute_name}" end
normalized_value(value)
click to toggle source
# File lib/relevium/form.rb, line 119 def normalized_value(value) return nil if value.nil? return value unless type return value if value.is_a?(type) cast_value_to_type(value) rescue ArgumentError => _e nil end