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
- #format(value) ⇒ Object
- #operation_label ⇒ Object
- #to_s ⇒ Object
- #value ⇒ Object
Instance Method Details
#as_associated? ⇒ Boolean
80 81 82 |
# File 'app/models/effective/report_column.rb', line 80 def as_associated? [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one].include?(as.to_sym) end |
#format(value) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/effective/report_column.rb', line 61 def format(value) return '' if value.blank? case as.to_sym when :boolean then value.to_s when :date then value.strftime('%F') 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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/effective/report_column.rb', line 88 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' else raise("unexpected operation: #{operation}") end end |
#to_s ⇒ Object
57 58 59 |
# File 'app/models/effective/report_column.rb', line 57 def to_s [name, operation_label, value].compact.join(' ').presence || 'report column' end |
#value ⇒ Object
84 85 86 |
# File 'app/models/effective/report_column.rb', line 84 def value value_date || value_decimal || value_integer || value_price || value_string.presence || value_associated.presence || value_boolean end |