Class: WillFilter::FilterContainer
- Inherits:
-
Object
- Object
- WillFilter::FilterContainer
show all
- Defined in:
- lib/will_filter/filter_container.rb
Direct Known Subclasses
Containers::Boolean, Containers::Date, Containers::DateRange, Containers::DateTime, Containers::DateTimeRange, Containers::Double, Containers::DoubleDelimited, Containers::DoubleRange, Containers::FilterList, Containers::List, Containers::Nil, Containers::Numeric, Containers::NumericDelimited, Containers::NumericRange, Containers::SingleDate, Containers::Text, Containers::TextDelimited
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filter, condition, operator, values) ⇒ FilterContainer
Returns a new instance of FilterContainer.
37
38
39
40
41
42
|
# File 'lib/will_filter/filter_container.rb', line 37
def initialize(filter, condition, operator, values)
@filter = filter
@condition = condition
@operator = operator
@values = values
end
|
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
35
36
37
|
# File 'lib/will_filter/filter_container.rb', line 35
def condition
@condition
end
|
#filter ⇒ Object
Returns the value of attribute filter.
35
36
37
|
# File 'lib/will_filter/filter_container.rb', line 35
def filter
@filter
end
|
#index ⇒ Object
Returns the value of attribute index.
35
36
37
|
# File 'lib/will_filter/filter_container.rb', line 35
def index
@index
end
|
#operator ⇒ Object
Returns the value of attribute operator.
35
36
37
|
# File 'lib/will_filter/filter_container.rb', line 35
def operator
@operator
end
|
#values ⇒ Object
Returns the value of attribute values.
35
36
37
|
# File 'lib/will_filter/filter_container.rb', line 35
def values
@values
end
|
Instance Method Details
#date(dt = value) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/will_filter/filter_container.rb', line 48
def date(dt = value)
return nil unless dt
Time.parse(dt).to_date
rescue
nil
end
|
#is_floating_point?(s) ⇒ Boolean
91
92
93
|
# File 'lib/will_filter/filter_container.rb', line 91
def is_floating_point?(s)
s.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+\Z/) == nil ? false : true
end
|
#is_numeric?(s) ⇒ Boolean
95
96
97
|
# File 'lib/will_filter/filter_container.rb', line 95
def is_numeric?(s)
s.to_s.match(/\A[-+]?[0-9]*\Z/) == nil ? false : true
end
|
#options ⇒ Object
used by the list based containers
69
70
71
|
# File 'lib/will_filter/filter_container.rb', line 69
def options
[]
end
|
#reset_values ⇒ Object
77
78
79
|
# File 'lib/will_filter/filter_container.rb', line 77
def reset_values
@values = []
end
|
#sanitized_value(index = 0) ⇒ Object
62
63
64
65
66
|
# File 'lib/will_filter/filter_container.rb', line 62
def sanitized_value(index = 0)
return '' if index >= values.size
return '' if values[index].blank?
values[index].to_s.gsub("'", "'")
end
|
#serialize_to_params(params, index) ⇒ Object
85
86
87
88
89
|
# File 'lib/will_filter/filter_container.rb', line 85
def serialize_to_params(params, index)
values.each_with_index do |v, v_index|
params["wf_v#{index}_#{v_index}"] = v
end
end
|
#template_name ⇒ Object
81
82
83
|
# File 'lib/will_filter/filter_container.rb', line 81
def template_name
self.class.name.underscore.split('/').last
end
|
#time(tm = value) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/will_filter/filter_container.rb', line 55
def time(tm = value)
return nil unless tm
Time.parse(tm)
rescue
nil
end
|
#validate ⇒ Object
73
74
75
|
# File 'lib/will_filter/filter_container.rb', line 73
def validate
return "Value must be provided" if value.blank?
end
|
#value ⇒ Object
44
45
46
|
# File 'lib/will_filter/filter_container.rb', line 44
def value
values.first
end
|