Class: Effective::ReportColumn
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::ReportColumn
- Defined in:
- app/models/effective/report_column.rb
Instance Method Summary collapse
- #as_associated? ⇒ Boolean
- #date_filter? ⇒ Boolean
-
#days_filter? ⇒ Boolean
Days Since functionality.
- #days_label ⇒ Object
- #format(value) ⇒ Object
- #operation_label ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Instance Method Details
#as_associated? ⇒ Boolean
95 96 97 |
# File 'app/models/effective/report_column.rb', line 95 def as_associated? [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one].include?(as.to_sym) end |
#date_filter? ⇒ Boolean
91 92 93 |
# File 'app/models/effective/report_column.rb', line 91 def date_filter? as == 'date' && operation.to_s.exclude?('days') end |
#days_filter? ⇒ Boolean
Days Since functionality
87 88 89 |
# File 'app/models/effective/report_column.rb', line 87 def days_filter? as == 'date' && operation.to_s.include?('days') end |
#days_label ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/effective/report_column.rb', line 127 def days_label return unless operation.present? case operation.to_sym when :days_ago_eq then 'days ago' when :days_ago_gteq then 'days ago' when :days_ago_lteq then 'days ago' else '' end end |
#format(value) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/effective/report_column.rb', line 67 def format(value) return '' if value.blank? case as.to_sym when :boolean then value.to_s when :date then value.try(:strftime, '%F') || value.to_s when :decimal then value.to_s when :integer then value.to_s when :price then '$' + ('%0.2f' % (value / 100.0)) when :string then value.to_s when :belongs_to then value.to_s when :belongs_to_polymorphic then value.to_s when :has_many then Array(value).map { |value| value.to_s }.join("\n\n") when :has_one then value.to_s else raise("unexpected as: #{as || 'nil'}") end end |
#operation_label ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/models/effective/report_column.rb', line 104 def operation_label return unless operation.present? case operation.to_sym when :eq then '=' when :not_eq then '!=' when :matches then '~=' when :does_not_match then '!~=' when :starts_with then 'starts with' when :ends_with then 'ends with' when :gt then '>' when :gteq then '>=' when :lt then '<' when :lteq then '<=' when :sql then 'sql' when :days_ago_eq then '=' when :days_ago_gteq then '>=' when :days_ago_lteq then '<=' else raise("unexpected operation: #{operation}") end end |
#to_s ⇒ Object
63 64 65 |
# File 'app/models/effective/report_column.rb', line 63 def to_s [name, operation_label, value, days_label].compact.join(' ').presence || 'report column' end |
#value ⇒ Object
99 100 101 102 |
# File 'app/models/effective/report_column.rb', line 99 def value return value_integer if days_filter? value_date || value_decimal || value_integer || value_price || value_string.presence || value_associated.presence || value_boolean end |