Class: Effective::ReportColumn

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/report_column.rb

Instance Method Summary collapse

Instance Method Details

#as_associated?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/effective/report_column.rb', line 89

def as_associated?
  [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one].include?(as.to_sym)
end

#date_filter?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/effective/report_column.rb', line 85

def date_filter?
  as == 'date' && operation.to_s.exclude?('days')
end

#days_filter?Boolean

Days Since functionality

Returns:

  • (Boolean)


81
82
83
# File 'app/models/effective/report_column.rb', line 81

def days_filter?
  as == 'date' && operation.to_s.include?('days')
end

#days_labelObject



121
122
123
124
125
126
127
128
129
# File 'app/models/effective/report_column.rb', line 121

def days_label
  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



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.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_labelObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/models/effective/report_column.rb', line 98

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_sObject



57
58
59
# File 'app/models/effective/report_column.rb', line 57

def to_s
  [name, operation_label, value, days_label].compact.join(' ').presence || 'report column'
end

#valueObject



93
94
95
96
# File 'app/models/effective/report_column.rb', line 93

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