class KonoUtils::SearchAttribute
Classe che mi rappresenta un attributo di ricerca Di default utilizza il tipo string come renderizzazione
* *Args* : - form_options -> Hash con opzioni da passare a formtastic - field_options -> Hash con opzioni: cast -> Proc per eseguire il cast del valore
Attributes
field[RW]
field_options[RW]
form_options[RW]
Public Class Methods
new(field, options = {})
click to toggle source
# File lib/kono_utils/search_attribute.rb, line 14 def initialize(field, options = {}) self.field = field self.field_options = {} unless options.is_a? Proc if options[:field_options] self.field_options = options[:field_options] options.delete(:field_options) end end self.form_options = options end
Public Instance Methods
cast_value(value)
click to toggle source
Esegue un casting dei valori rispetto al tipo di campo da utilizzare per formtastic
# File lib/kono_utils/search_attribute.rb, line 30 def cast_value(value) return value if value.blank? return value if form_options.is_a? Proc return field_options[:cast].call(value) if field_options[:cast].is_a? Proc case form_options[:as] when :bs_datetimepicker if value.is_a? String DateTime.parse(value) elsif value.is_a? Date value.to_time else value end when :bs_datepicker if value.is_a? String DateTime.parse(value).to_date elsif value.is_a? DateTime value.to_date else value end else value end end