module DCA::Models::BinderHelper::ClassMethods
Public Instance Methods
convert(value, type)
click to toggle source
# File lib/dca/models/binder_helper.rb, line 7 def convert value, type case type when :integer value.to_s.gsub(/[^\d.,]/,'').gsub(/,/,'.').to_i when :float value.to_s.gsub(/[^\d.,]/,'').gsub(/,/,'.').to_f when :string value.to_s.strip when :symbol value.to_s.to_sym when :datetime DateTime.parse(value).to_time.utc unless value.nil? else value end end
find_type(object, field, polymorphic = nil)
click to toggle source
# File lib/dca/models/binder_helper.rb, line 37 def find_type object, field, polymorphic = nil type_name = field.to_s.singularize.camelize type_name = "#{object.send(polymorphic).to_s.camelize}#{type_name}" if polymorphic type = type_name.safe_constantize type = "#{object.class.to_s.deconstantize}::#{type_name}".constantize if type.nil? type end
parse_options(object, value, options)
click to toggle source
# File lib/dca/models/binder_helper.rb, line 24 def parse_options object, value, options result = value if result.nil? result = options[:default] unless options[:default].nil? else result = value[options[:regex], 1] unless options[:regex].nil? end result = object.send(options[:parser], result) unless options[:parser].nil? result end