Class: QueryReport::FilterModule::Comparator
- Inherits:
-
Object
- Object
- QueryReport::FilterModule::Comparator
- Defined in:
- lib/query_report/comparator.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #has_default? ⇒ Boolean
-
#initialize(filter, type, name, default = nil) ⇒ Comparator
constructor
A new instance of Comparator.
-
#objectified_param_value ⇒ Object
convert param value which is a string to object like date and boolean.
- #param_value ⇒ Object
- #search_key ⇒ Object
- #search_tag_name ⇒ Object
- #stringified_default ⇒ Object
Constructor Details
#initialize(filter, type, name, default = nil) ⇒ Comparator
Returns a new instance of Comparator.
9 10 11 |
# File 'lib/query_report/comparator.rb', line 9 def initialize(filter, type, name, default=nil) @filter, @type, @name, @default = filter, type, name, default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
7 8 9 |
# File 'lib/query_report/comparator.rb', line 7 def default @default end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
7 8 9 |
# File 'lib/query_report/comparator.rb', line 7 def filter @filter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/query_report/comparator.rb', line 7 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/query_report/comparator.rb', line 7 def type @type end |
Instance Method Details
#has_default? ⇒ Boolean
25 26 27 |
# File 'lib/query_report/comparator.rb', line 25 def has_default? !@default.nil? end |
#objectified_param_value ⇒ Object
convert param value which is a string to object like date and boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/query_report/comparator.rb', line 41 def objectified_param_value @objectified_param_value ||= case @filter.type when :date format = I18n.t("date.formats.#{QueryReport.config.date_format}") param_value.kind_of?(String) ? (Date.strptime(param_value, format) rescue param_value) : param_value when :datetime param_value.kind_of?(String) ? Time.zone.parse(param_value) : param_value when :boolean param_value.to_boolean else param_value end end |
#param_value ⇒ Object
21 22 23 |
# File 'lib/query_report/comparator.rb', line 21 def param_value @filter.params[@filter.params_key] ? @filter.params[@filter.params_key][search_key] : stringified_default end |
#search_key ⇒ Object
13 14 15 |
# File 'lib/query_report/comparator.rb', line 13 def search_key "#{@filter.column.to_s}_#{@type}".to_sym end |
#search_tag_name ⇒ Object
17 18 19 |
# File 'lib/query_report/comparator.rb', line 17 def search_tag_name "#{@filter.params_key}[#{search_key.to_s}]" end |
#stringified_default ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/query_report/comparator.rb', line 29 def stringified_default @stringified_default ||= case @filter.type when :date @default.kind_of?(String) ? @default : (I18n.l(@default, format: QueryReport.config.date_format) rescue @default) when :datetime @default.kind_of?(String) ? @default : (I18n.l(@default, format: QueryReport.config.datetime_format) rescue @default) else @default.to_s end end |