Class: KonoUtils::SearchAttribute
- Inherits:
-
Object
- Object
- KonoUtils::SearchAttribute
- Defined in:
- lib/kono_utils/search_attribute.rb
Overview
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
-
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#field_options ⇒ Object
Returns the value of attribute field_options.
-
#form_options ⇒ Object
Returns the value of attribute form_options.
Instance Method Summary collapse
-
#cast_value(value) ⇒ Object
Esegue un casting dei valori rispetto al tipo di campo da utilizzare per formtastic.
-
#initialize(field, options = {}) ⇒ SearchAttribute
constructor
A new instance of SearchAttribute.
Constructor Details
#initialize(field, options = {}) ⇒ SearchAttribute
Returns a new instance of SearchAttribute.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kono_utils/search_attribute.rb', line 14 def initialize(field, = {}) self.field = field self. = {} unless .is_a? Proc if [:field_options] self. = [:field_options] .delete(:field_options) end end self. = end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
12 13 14 |
# File 'lib/kono_utils/search_attribute.rb', line 12 def field @field end |
#field_options ⇒ Object
Returns the value of attribute field_options.
12 13 14 |
# File 'lib/kono_utils/search_attribute.rb', line 12 def @field_options end |
#form_options ⇒ Object
Returns the value of attribute form_options.
12 13 14 |
# File 'lib/kono_utils/search_attribute.rb', line 12 def @form_options end |
Instance Method Details
#cast_value(value) ⇒ Object
Esegue un casting dei valori rispetto al tipo di campo da utilizzare per formtastic
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kono_utils/search_attribute.rb', line 30 def cast_value(value) return value if value.blank? return value if .is_a? Proc return [:cast].call(value) if [:cast].is_a? Proc case [: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 |