Created
January 23, 2013 19:14
-
-
Save albus522/4611754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/company.rb b/app/models/company.rb | |
index 458a3af..1773c20 100644 | |
--- a/app/models/company.rb | |
+++ b/app/models/company.rb | |
@@ -125,16 +125,27 @@ class Company < ActiveRecord::Base | |
cond_params = {} | |
joins = [] | |
- if !params[:duns_number].blank? | |
- cond_strings << "duns = :duns_number" | |
- cond_params[:duns_number] = params[:duns_number] | |
+ { | |
+ :duns_number => ['duns', '='], | |
+ :employment_min => ['total_employees', '>='], | |
+ :employment_max => ['total_employees', '<='], | |
+ :sales_growth_min => ['sales_growth', '>='], | |
+ :sales_growth_max => ['sales_growth', '<='], | |
+ :employment_growth_min => ['employment_growth', '>='], | |
+ :employment_growth_max => ['employment_growth', '<='], | |
+ :headquarters => ['headquarters', '='], | |
+ :zip_code => ['companies.postal_code', '='] | |
+ }.each do |param, (field, op)| | |
+ if !params[param].blank? | |
+ cond_strings << "#{field} #{op} :#{param}" | |
+ cond_params[param] = params[param] | |
+ end | |
end | |
if !params[:industry].blank? | |
cond_strings << "industries.number LIKE :industry" | |
cond_params[:industry] = params[:industry] + '%' | |
joins << :primary_industry | |
end | |
- # cond_params[:industry] = params[:industry] unless params[:industry].blank? | |
if !params[:sales_min].blank? | |
cond_strings << "sales_cents >= :sales_min" | |
cond_params[:sales_min] = params[:sales_min].to_i * 100 | |
@@ -143,34 +154,6 @@ class Company < ActiveRecord::Base | |
cond_strings << "sales_cents <= :sales_max" | |
cond_params[:sales_max] = params[:sales_max].to_i * 100 | |
end | |
- if !params[:employment_min].blank? | |
- cond_strings << "total_employees >= :employment_min" | |
- cond_params[:employment_min] = params[:employment_min] | |
- end | |
- if !params[:employment_max].blank? | |
- cond_strings << "total_employees <= :employment_max" | |
- cond_params[:employment_max] = params[:employment_max] | |
- end | |
- if !params[:sales_growth_min].blank? | |
- cond_strings << "sales_growth >= :sales_growth_min" | |
- cond_params[:sales_growth_min] = params[:sales_growth_min] | |
- end | |
- if !params[:sales_growth_max].blank? | |
- cond_strings << "sales_growth <= :sales_growth_max" | |
- cond_params[:sales_growth_max] = params[:sales_growth_max] | |
- end | |
- if !params[:employment_growth_min].blank? | |
- cond_strings << "employment_growth >= :employment_growth_min" | |
- cond_params[:employment_growth_min] = params[:employment_growth_min] | |
- end | |
- if !params[:employment_growth_max].blank? | |
- cond_strings << "employment_growth <= :employment_growth_max" | |
- cond_params[:employment_growth_max] = params[:employment_growth_max] | |
- end | |
- if !params[:headquarters].blank? | |
- cond_strings << "headquarters = :headquarters" | |
- cond_params[:headquarters] = params[:headquarters] | |
- end | |
if !params[:city].blank? | |
parts = [] | |
params[:city].split(/, */).each_with_index do |city, index| | |
@@ -215,10 +198,6 @@ class Company < ActiveRecord::Base | |
end | |
cond_strings << "(#{parts * ' OR '})" | |
end | |
- if !params[:zip_code].blank? | |
- cond_strings << "companies.postal_code = :zip_code" | |
- cond_params[:zip_code] = params[:zip_code] | |
- end | |
if !params[:area_code].blank? | |
cond_strings << "phones.number LIKE :area_code" | |
cond_params[:area_code] = params[:area_code] + '%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment