Class: Effective::QuestionAnswer

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

Constant Summary collapse

OPERATIONS =
[
  'Equal to', 
  'Within range', 
  'Less than',
  'Less than or equal to', 
  'Greater than',
  'Greater than or equal to', 
  'Contains', 
  'Does not contain'
]

Instance Method Summary collapse

Instance Method Details

#answerObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/effective/question_answer.rb', line 132

def answer
  if operation == 'Within range'
    return (date_begin..date_end) if question.date?
    return (decimal_begin..decimal_end) if question.decimal?
    return (number_begin..number_end) if question.number?
    return (percentage_begin..percentage_end) if question.percentage?
    return (price_begin..price_end) if question.price?
  else
    return date if question.date?
    return decimal if question.decimal?
    return email if question.email?
    return number if question.number?
    return percentage if question.percentage?
    return price if question.price?
    return long_answer if question.long_answer?
    return short_answer if question.short_answer?
  end

  raise("unknown operation: #{operation}")
end

#contains?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'app/models/effective/question_answer.rb', line 157

def contains?
  operation == 'Contains'
end

#does_not_contain?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'app/models/effective/question_answer.rb', line 161

def does_not_contain?
  operation == 'Does not contain'
end

#equals?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'app/models/effective/question_answer.rb', line 153

def equals?
  operation == 'Equal to'
end

#gt?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'app/models/effective/question_answer.rb', line 173

def gt?
  operation == 'Greater than'
end

#gteq?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'app/models/effective/question_answer.rb', line 181

def gteq?
  operation == 'Greater than or equal to'
end

#lt?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'app/models/effective/question_answer.rb', line 169

def lt?
  operation == 'Less than'
end

#lteq?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'app/models/effective/question_answer.rb', line 177

def lteq?
  operation == 'Less than or equal to'
end

#operations(category) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/models/effective/question_answer.rb', line 109

def operations(category)
  case category
  when 'Choose one' then nil
  when 'Select all that apply' then nil
  when 'Select up to 1' then nil 
  when 'Select up to 2' then nil
  when 'Select up to 3' then nil
  when 'Select up to 4' then nil
  when 'Select up to 5' then nil
  when 'Upload File' then nil
  when 'Date' then OPERATIONS - ['Contains', 'Does not contain']
  when 'Decimal' then OPERATIONS - ['Contains', 'Does not contain']
  when 'Number' then OPERATIONS - ['Contains', 'Does not contain']
  when 'Percentage' then OPERATIONS - ['Contains', 'Does not contain']
  when 'Price' then OPERATIONS - ['Contains', 'Does not contain']
  when 'Email' then ['Equal to', 'Contains', 'Does not contain']
  when 'Long Answer' then ['Equal to', 'Contains', 'Does not contain']
  when 'Short Answer' then ['Equal to', 'Contains', 'Does not contain']
  else
    raise("unknown operations for category: #{category}")
  end
end

#to_sObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/effective/question_answer.rb', line 83

def to_s
  return '' unless question.present?
  return '-' unless operations(question.category).present?

  case operation
  when 'Equal to'
    "Equal to #{format_value(answer)}"
  when 'Within range'
    "Between #{format_value(answer.begin)} and #{format_value(answer.end)}"
  when 'Less than'
    "Less than #{format_value(answer)}"
  when 'Less than or equal to'
    "Less than or equal to #{format_value(answer)}"
  when 'Greater than'
    "Greater than #{format_value(answer)}"
  when 'Greater than or equal to'
    "Greater than or equal to #{format_value(answer)}"
  when 'Contains'
    "Contains #{format_value(answer)}"
  when 'Does not contain'
    "Does not contain #{format_value(answer)}"
  else
    raise("unknown operation: #{operation}")
  end
end

#within_range?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'app/models/effective/question_answer.rb', line 165

def within_range?
  operation == 'Within range'
end