28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/models/search.rb', line 28
def description
conditions = []
conditions << "Are tagged with #{tagging}." if tagging.present?
conditions << "Bought tickets for #{event.name}." if event_id.present?
if zip.present? || state.present?
locations = []
locations << state if state.present?
locations << "the zipcode of #{zip}" if zip.present?
conditions << "Are located within #{locations.to_sentence}."
end
if min_lifetime_value.present? && max_lifetime_value.present?
conditions << "Have a lifetime value between $#{min_lifetime_value} and $#{max_lifetime_value}."
elsif min_lifetime_value.present?
conditions << "Have a minimum lifetime value of $#{min_lifetime_value}."
elsif max_lifetime_value.present?
conditions << "Have a maximum lifetime value of $#{max_lifetime_value}."
end
unless discount_code.blank?
conditions << ((discount_code == Discount::ALL_DISCOUNTS_STRING) ? "Used any discount code" : "Used discount code #{discount_code}.")
end
unless [min_donations_amount, max_donations_amount, min_donations_date, max_donations_date].all?(&:blank?)
if min_donations_amount.present? && max_donations_amount.present?
string = "Made between $#{min_donations_amount} and $#{max_donations_amount} in donations"
elsif min_donations_amount.present?
string = "Made a total minimum of $#{min_donations_amount} in donations"
elsif max_donations_amount.present?
string = "Made no more than $#{max_donations_amount} in total donations"
else
string = "Made any donations"
end
if min_donations_date.present? && max_donations_date.present?
string << " from #{min_donations_date.strftime('%D')} to #{max_donations_date.strftime('%D')}."
elsif min_donations_date.present?
string << " after #{min_donations_date.strftime('%D')}."
elsif max_donations_date.present?
string << " before #{max_donations_date.strftime('%D')}."
else
string << " overall."
end
conditions << string
end
if conditions.blank?
return "All people."
else
return "People that: <ul>" + conditions.collect{|c| "<li>#{c}</li>"}.join + "</ul>"
end
end
|