kirgudu_refs 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/kirgudu_refs/model_basic_properties.rb +69 -0
  3. data/app/models/kirgudu_refs/base_model.rb +0 -8
  4. data/app/models/kirgudu_refs/finances.rb +7 -0
  5. data/app/models/kirgudu_refs/finances/bank.rb +116 -0
  6. data/app/models/kirgudu_refs/globe/city.rb +57 -57
  7. data/app/models/kirgudu_refs/globe/country.rb +69 -53
  8. data/app/models/kirgudu_refs/globe/region.rb +20 -25
  9. data/app/models/kirgudu_refs/globe/state.rb +58 -61
  10. data/app/models/kirgudu_refs/globe/subway_line.rb +29 -25
  11. data/app/models/kirgudu_refs/globe/subway_station.rb +43 -40
  12. data/app/models/kirgudu_refs/globe/timezone.rb +40 -5
  13. data/app/models/kirgudu_refs/it.rb +1 -1
  14. data/app/models/kirgudu_refs/it/encoding.rb +31 -28
  15. data/app/models/kirgudu_refs/it/hosting_type.rb +50 -0
  16. data/app/models/kirgudu_refs/it/operating_system.rb +34 -24
  17. data/app/models/kirgudu_refs/it/operating_system_family.rb +55 -4
  18. data/app/models/kirgudu_refs/it/processor_architecture.rb +32 -5
  19. data/app/models/kirgudu_refs/it/top_level_domain.rb +26 -0
  20. data/app/models/kirgudu_refs/it/website_type.rb +49 -0
  21. data/app/models/kirgudu_refs/national/currency.rb +59 -52
  22. data/app/models/kirgudu_refs/national/language.rb +84 -79
  23. data/app/models/kirgudu_refs/shops.rb +1 -1
  24. data/app/models/kirgudu_refs/shops/manufacturer.rb +37 -33
  25. data/config/database.yml +10 -0
  26. data/db/migrate/20130831122828_create_kirgudu_refs_it_operating_system_families.rb +12 -4
  27. data/db/migrate/20130831122900_create_kirgudu_refs_it_encodings.rb +12 -3
  28. data/db/migrate/20130831123418_create_kirgudu_refs_globe_cities.rb +17 -7
  29. data/db/migrate/20130831123443_create_kirgudu_refs_globe_regions.rb +17 -10
  30. data/db/migrate/20130831123613_create_kirgudu_refs_globe_states.rb +15 -8
  31. data/db/migrate/20130831123640_create_kirgudu_refs_globe_countries.rb +15 -7
  32. data/db/migrate/20130831124432_create_kirgudu_refs_globe_subway_lines.rb +18 -5
  33. data/db/migrate/20130831124648_create_kirgudu_refs_globe_subway_stations.rb +15 -6
  34. data/db/migrate/20130831125136_create_kirgudu_refs_globe_timezones.rb +13 -4
  35. data/db/migrate/20130831125626_create_kirgudu_refs_it_operating_systems.rb +14 -6
  36. data/db/migrate/20130831125703_create_kirgudu_refs_it_processor_architectures.rb +12 -3
  37. data/db/migrate/20130831130259_create_kirgudu_refs_national_currencies.rb +14 -6
  38. data/db/migrate/20130831130350_create_kirgudu_refs_national_languages.rb +11 -4
  39. data/db/migrate/20130831130436_create_kirgudu_refs_shops_manufacturers.rb +18 -6
  40. data/db/migrate/20140111155321_create_kirgudu_refs_it_website_types.rb +32 -0
  41. data/db/migrate/20140111155332_create_kirgudu_refs_it_hosting_types.rb +34 -0
  42. data/db/migrate/20140113072335_create_kirgudu_refs_it_top_level_domains.rb +36 -0
  43. data/db/migrate/20140215071954_create_kirgudu_refs_finances_banks.rb +60 -0
  44. data/test/dummy/config/application.rb +1 -1
  45. data/test/dummy/db/development.sqlite3 +0 -0
  46. data/test/dummy/db/schema.rb +551 -0
  47. data/test/dummy/log/development.log +285 -0
  48. data/test/fixtures/kirgudu_refs/finances/banks.yml +7 -0
  49. data/test/fixtures/kirgudu_refs/it/top_level_domains.yml +11 -0
  50. data/test/models/kirgudu_refs/finances/bank_test.rb +9 -0
  51. data/test/models/kirgudu_refs/it/top_level_domain_test.rb +9 -0
  52. metadata +37 -27
  53. data/db/migrate/20130902065049_fix_id_in_it_operating_system_families.rb +0 -9
  54. data/db/migrate/20130902065101_fix_id_in_it_encodings.rb +0 -9
  55. data/db/migrate/20130902065111_fix_id_in_globe_cities.rb +0 -10
  56. data/db/migrate/20130902065117_fix_id_in_globe_countries.rb +0 -9
  57. data/db/migrate/20130902065123_fix_id_in_globe_states.rb +0 -9
  58. data/db/migrate/20130902065131_fix_id_in_globe_regions.rb +0 -9
  59. data/db/migrate/20130902065943_fix_id_in_globe_subway_lines.rb +0 -9
  60. data/db/migrate/20130902065951_fix_id_in_globe_subway_stations.rb +0 -9
  61. data/db/migrate/20130902070323_fix_id_in_globe_timezones.rb +0 -9
  62. data/db/migrate/20130902070557_fix_id_in_national_currency.rb +0 -9
  63. data/db/migrate/20130902070604_fix_id_in_national_language.rb +0 -9
  64. data/db/migrate/20130902070628_fix_id_in_it_operating_system.rb +0 -9
  65. data/db/migrate/20130902070640_fix_id_in_it_processor_architecture.rb +0 -9
  66. data/db/migrate/20130902070659_fix_id_in_shops_manufacturer.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2921184033f761699f1a1a7a2c09378a020ce0f
4
- data.tar.gz: 2a783224e7ae4cc4a01b600e038fae7b448d79eb
3
+ metadata.gz: 01ea468d9e566ff2298438e7e21d6d3ead8afd9d
4
+ data.tar.gz: a52a891c52fc92c0dae316fcb6b162c178013394
5
5
  SHA512:
6
- metadata.gz: 6d52401653a48fb69f30b9f934024206fc73f854af0deda6ecf5b72f2fbe162f05636f53009389ed9fc0ca6ffd884f9c0b39fe3082ee2869418222a72b38a769
7
- data.tar.gz: 24e0c403836194ae67b061840a87d26cbffe376052c38b86dc2edbbc6342a485913136be13e807fc03de0214f85d484b6a71936702de1cddd9ec7099fb8416ac
6
+ metadata.gz: 5f7b366f0002435e253ea97881a08f577c8100025a8816095ed06133cd55501c0789aa94cf8eecd009620fa67fefc1258f6c78301286804b7aff808c86dd0cb5
7
+ data.tar.gz: 7c47ec3bd10b5ea48a3450959a95e880b3d59bce3af7091ca2d6847e069330099bdaf808d517de19f6573a875bc2317a3ce131c26ad1cb96b4e645bb880f9aca
@@ -170,6 +170,75 @@ module KirguduRefs
170
170
  end
171
171
  end
172
172
 
173
+ module ProcessorArchitectureID
174
+ def self.included(base)
175
+ base.belongs_to :processor_architecture, class_name: ::KirguduRefs::It::ProcessorArchitecture, foreign_key: :processor_architecture_id
176
+ base.scope :by_processor_architecture, lambda { |value| base.where(processor_architecture_id: value) if value }
177
+
178
+ base.class_eval do
179
+ include InstanceMethods
180
+ end
181
+ end
182
+
183
+ module InstanceMethods
184
+ def processor_architecture_name
185
+ processor_architecture.name if processor_architecture
186
+ end
187
+ end
188
+ end
189
+
190
+
191
+ module OperatingSystemFamilyID
192
+ def self.included(base)
193
+ base.belongs_to :operating_system_family, class_name: ::KirguduRefs::It::OperatingSystemFamily, foreign_key: :operating_system_family_id
194
+ base.scope :by_operating_system_family, lambda { |value| base.where(operating_system_family_id: value) if value }
195
+
196
+ base.class_eval do
197
+ include InstanceMethods
198
+ end
199
+ end
200
+
201
+ module InstanceMethods
202
+ def operating_system_family_name
203
+ operating_system_family.name if operating_system_family
204
+ end
205
+ end
206
+ end
207
+
208
+
209
+ module OperatingSystemID
210
+ def self.included(base)
211
+ base.belongs_to :operating_system, class_name: ::KirguduRefs::It::OperatingSystem, foreign_key: :operating_system_id
212
+ base.scope :by_operating_system, lambda { |value| base.where(operating_system_id: value) if value }
213
+
214
+ base.class_eval do
215
+ include InstanceMethods
216
+ end
217
+ end
218
+
219
+ module InstanceMethods
220
+ def operating_system_name
221
+ operating_system.name if operating_system
222
+ end
223
+ end
224
+ end
225
+
226
+ module BankID
227
+ def self.included(base)
228
+ base.belongs_to :bank, class_name: ::KirguduRefs::Finances::Bank, foreign_key: :bank_id
229
+ base.scope :by_bank, lambda { |value| base.where(bank_id: value) if value }
230
+
231
+ base.class_eval do
232
+ include InstanceMethods
233
+ end
234
+ end
235
+
236
+ module InstanceMethods
237
+ def bank_name
238
+ bank.short_name || bank.name if bank
239
+ end
240
+ end
241
+ end
173
242
 
174
243
  end
175
244
  end
@@ -2,13 +2,5 @@ class KirguduRefs::BaseModel < ::KirguduBase::BaseModel
2
2
 
3
3
  self.abstract_class = true
4
4
 
5
- def self.apply_filters_to_query(query, filters={})
6
- filters ||={}
7
5
 
8
- query = query
9
- .with_slug(filters[:seo_tag])
10
-
11
-
12
- super(query, filters)
13
- end
14
6
  end
@@ -0,0 +1,7 @@
1
+ module KirguduRefs
2
+ module Finances
3
+ def self.table_name_prefix
4
+ 'kirgudu_refs_finances_'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,116 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module KirguduRefs
4
+ module Finances
5
+ class Bank < ::KirguduRefs::BaseModel
6
+
7
+
8
+ ########################################## RELATIONS ########################################
9
+
10
+ include ::KirguduBase::Models::BasicProperties::Portal
11
+ include ::KirguduBase::Models::BasicProperties::CreatedBy
12
+ include ::KirguduBase::Models::BasicProperties::UpdatedBy
13
+
14
+ include ::KirguduRefs::ModelBasicProperties::CountryID
15
+ include ::KirguduRefs::ModelBasicProperties::StateID
16
+ include ::KirguduRefs::ModelBasicProperties::CityID
17
+
18
+ ########################################## VALIDATIONS #######################################
19
+
20
+
21
+ validates_presence_of :name, :bik, :correspondent_account
22
+ validates_uniqueness_of :name, :bik, :correspondent_account, scope: :portal_id, case_sensitive: false
23
+ validates_uniqueness_of :short_name, scope: :portal_id, case_sensitive: false, allow_blank: true
24
+ validates_uniqueness_of :registration_number, scope: :portal_id, allow_nil: true
25
+
26
+ validates_length_of :bik, is: 9
27
+ validates_length_of :correspondent_account, is: 20
28
+ validates_length_of :name, maximum: 180
29
+ validates_length_of :short_name, maximum: 128, allow_blank: true
30
+ validates_length_of :registration_number, maximum: 40, allow_blank: true
31
+ validates_length_of :ogrn, is: 13, allow_blank: true
32
+
33
+ validates_length_of :address_actual, :address_legal, maximum: 256, allow_blank: true
34
+
35
+ validates_length_of :phone1, :phone2, :phone3, :phone4, maximum: 20, allow_blank: true
36
+ validates_length_of :telex, :swift, maximum: 50, allow_blank: true
37
+
38
+
39
+ validates_inclusion_of :foundation_year, in: (1900..Date.today.year).to_a, allow_nil: true
40
+
41
+ ######################################### SCOPES #############################################
42
+
43
+ include ::KirguduBase::Models::Scopes::WithName
44
+
45
+ scope :with_capital_min, lambda { |value| where { authorised_capital >= value } if value }
46
+ scope :with_capital_max, lambda { |value| where { authorised_capital <= value } if value }
47
+ scope :with_foundation_year_min, lambda { |value| where { foundation_year >= value } if value }
48
+ scope :with_foundation_year_max, lambda { |value| where { foundation_year <= value } if value }
49
+
50
+
51
+ scope :with_keyword, lambda { |value|
52
+ if value
53
+ value = value.gsub("%", " ").strip
54
+ like_value ="%#{value}%"
55
+ where { (name.like like_value) | (short_name.like like_value) | (bik.like like_value) }
56
+ end
57
+ }
58
+ scope :with_short_name, lambda { |value|
59
+ if value
60
+ value = value.gsub("%", " ").strip
61
+ like_value ="%#{value}%"
62
+ where { short_name.like like_value }
63
+ end
64
+ }
65
+ scope :with_bik, lambda { |value|
66
+ if value
67
+ value = value.gsub("%", " ").strip
68
+ like_value ="%#{value}%"
69
+ where { bik.like like_value }
70
+ end
71
+ }
72
+ scope :with_correspondent_account, lambda { |value|
73
+ if value
74
+ value = value.gsub("%", " ").strip
75
+ like_value ="%#{value}%"
76
+ where { correspondent_account.like like_value }
77
+ end
78
+ }
79
+ scope :with_swift, lambda { |value|
80
+ if value
81
+ value = value.gsub("%", " ").strip
82
+ like_value ="%#{value}%"
83
+ where { swift.like like_value }
84
+ end
85
+ }
86
+
87
+
88
+ def self.apply_filters_to_query(query, filters)
89
+ filters ||= {}
90
+
91
+ query = query
92
+ .with_swift(filters[:swift])
93
+ .with_bik(filters[:bik])
94
+ .with_short_name(filters[:short_name])
95
+ .with_capital_min(filters[:capital_min])
96
+ .with_capital_min(filters[:capital_max])
97
+ .with_foundation_year_min(filters[:foundation_year_min])
98
+ .with_foundation_year_max(filters[:foundation_year_max])
99
+ .by_country(filters[:country_id])
100
+ .by_state(filters[:state_id])
101
+ .by_city(filters[:city_id])
102
+
103
+ super(query, filters)
104
+ end
105
+
106
+ def name_for_breadcrumbs
107
+ self.short_name
108
+ end
109
+
110
+ def to_s
111
+ self.short_name
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -1,78 +1,78 @@
1
1
  module KirguduRefs
2
- class Globe::City < ::KirguduRefs::BaseModel
3
- attr_accessible :area, :coordinates, :country_id, :name, :phone_code, :population, :region_id, :slug, :state_id, :description, :meta_keywords, :meta_description, :image_id
2
+ module Globe
3
+ class City < ::KirguduRefs::BaseModel
4
4
 
5
+ ########################################## RELATIONS ########################################
5
6
 
7
+ include ::KirguduBase::Models::BasicProperties::Portal
8
+ include ::KirguduBase::Models::BasicProperties::CreatedBy
9
+ include ::KirguduBase::Models::BasicProperties::UpdatedBy
6
10
 
7
- validates_presence_of :name, :country_id, :state_id, :slug
8
- validates_uniqueness_of :name, :slug, scope: :state_id
9
- validate_as_seo_tag :slug
11
+ include ::KirguduRefs::ModelBasicProperties::CountryID
12
+ include ::KirguduRefs::ModelBasicProperties::StateID
13
+ include ::KirguduRefs::ModelBasicProperties::RegionID
10
14
 
11
- include ::KirguduRefs::ModelBasicProperties::CountryID
12
- include ::KirguduRefs::ModelBasicProperties::StateID
13
- include ::KirguduRefs::ModelBasicProperties::RegionID
15
+ ########################################## VALIDATIONS #######################################
14
16
 
17
+ validates_presence_of :name, :country_id, :state_id, :slug
18
+ validates_uniqueness_of :name, :slug, scope: :state_id
15
19
 
16
- has_many :subway_lines, class_name: ::KirguduRefs::Globe::SubwayLine, foreign_key: :city_id, dependent: :destroy
20
+ validates_length_of :name, maximum: 128, allow_blank: true
21
+ validates_length_of :slug, maximum: 128, allow_blank: true
22
+ validate_as_seo_tag :slug
17
23
 
24
+ validates_length_of :meta_keywords, maximum: 200, allow_blank: true
25
+ validates_length_of :meta_description, maximum: 200, allow_blank: true
18
26
 
19
- scope :with_area_min, lambda { |value| where { area >= value } if value }
20
- scope :with_area_max, lambda { |value| where { area <= value } if value }
21
- scope :with_population_min, lambda { |value| where { population >= value } if value }
22
- scope :with_population_max, lambda { |value| where { population <= value } if value }
27
+ has_many :subway_lines, class_name: ::KirguduRefs::Globe::SubwayLine, foreign_key: :city_id, dependent: :destroy
23
28
 
24
- scope :with_keyword, lambda { |value|
25
- if value
26
- value = value.gsub('%', ' ').strip
27
- like_value ="%#{value}%"
28
- where { (name.like like_value) | (slug.like like_value) }
29
- end
30
- }
31
- scope :with_name, lambda { |value|
32
- if value
33
- value = value.gsub('%', ' ').strip
34
- like_value ="%#{value}%"
35
- where { name.like like_value }
36
- end
37
- }
38
- scope :with_slug, lambda { |value|
39
- if value
40
- value = value.gsub('%', ' ').strip
41
- like_value ="%#{value}%"
42
- where { slug.like like_value }
43
- end
44
- }
29
+ ########################################### SCOPES #########################################
45
30
 
31
+ include ::KirguduBase::Models::Scopes::WithName
32
+ include ::KirguduBase::Models::Scopes::WithSlug
46
33
 
47
- def self.apply_filters_to_query(query, filters={})
48
- filters ||= {}
34
+ scope :with_area_min, lambda { |value| where { area >= value } if value }
35
+ scope :with_area_max, lambda { |value| where { area <= value } if value }
36
+ scope :with_population_min, lambda { |value| where { population >= value } if value }
37
+ scope :with_population_max, lambda { |value| where { population <= value } if value }
49
38
 
50
- query = query
51
- .with_keyword(filters[:keyword])
52
- .with_area_min(filters[:area_min])
53
- .with_area_max(filters[:area_max])
54
- .with_population_min(filters[:population_min])
55
- .with_population_max(filters[:population_max])
56
- .by_country(filters[:country_id])
57
- .by_state(filters[:state_id])
58
- .by_region(filters[:region_id])
39
+ scope :with_keyword, lambda { |value|
40
+ if value
41
+ value = value.gsub('%', ' ').strip
42
+ like_value ="%#{value}%"
43
+ where { (name.like like_value) | (slug.like like_value) }
44
+ end
45
+ }
59
46
 
60
- super(query, filters)
61
- end
47
+ def self.apply_filters_to_query(query, filters={})
48
+ filters ||= {}
62
49
 
50
+ query = query
51
+ .with_area_min(filters[:area_min])
52
+ .with_area_max(filters[:area_max])
53
+ .with_population_min(filters[:population_min])
54
+ .with_population_max(filters[:population_max])
55
+ .by_country(filters[:country_id])
56
+ .by_state(filters[:state_id])
57
+ .by_region(filters[:region_id])
63
58
 
64
- def capital_name
65
- capital.name if capital
66
- end
59
+ super(query, filters)
60
+ end
67
61
 
68
- def name_with_country_name
69
- "#{name} (#{country_name})"
70
- end
71
62
 
72
- def name_with_country_name_and_state
73
- "#{name} (#{country_name}, #{region_name})"
74
- end
63
+ def capital_name
64
+ capital.name if capital
65
+ end
75
66
 
67
+ def name_with_country_name
68
+ "#{name} (#{country_name})"
69
+ end
76
70
 
71
+ def name_with_country_name_and_state
72
+ "#{name} (#{country_name}, #{region_name})"
73
+ end
74
+
75
+
76
+ end
77
77
  end
78
- end
78
+ end
@@ -1,79 +1,95 @@
1
1
  module KirguduRefs
2
- class Globe::Country < ::KirguduRefs::BaseModel
2
+ module Globe
3
+ class Country < ::KirguduRefs::BaseModel
3
4
 
5
+ ########################################## RELATIONS ########################################
4
6
 
5
- attr_accessible :area, :iso2, :iso3, :name, :phone_code, :population, :slug, :currency_id, :capital_id, :meta_description, :meta_keywords, :description, :image_id
7
+ include ::KirguduBase::Models::BasicProperties::Portal
8
+ include ::KirguduBase::Models::BasicProperties::CreatedBy
9
+ include ::KirguduBase::Models::BasicProperties::UpdatedBy
6
10
 
7
- before_validation :normalize_values
11
+ include ::KirguduRefs::ModelBasicProperties::CountryID
12
+ include ::KirguduRefs::ModelBasicProperties::StateID
13
+ include ::KirguduRefs::ModelBasicProperties::RegionID
8
14
 
15
+ include ::KirguduRefs::ModelBasicProperties::CurrencyID
9
16
 
17
+ belongs_to :capital, class_name: ::KirguduRefs::Globe::City, foreign_key: :capital_id
18
+ #belongs_to :image, class_name: ::ErpZone::Common::Image, foreign_key: :image_id
10
19
 
11
- include ::KirguduRefs::ModelBasicProperties::CurrencyID
20
+ has_many :states, class_name: ::KirguduRefs::Globe::State, foreign_key: :country_id, dependent: :destroy
21
+ has_many :regions, class_name: ::KirguduRefs::Globe::Region, foreign_key: :country_id, dependent: :destroy
22
+ has_many :cities, class_name: ::KirguduRefs::Globe::City, foreign_key: :country_id, dependent: :destroy
12
23
 
24
+ ########################################## VALIDATIONS #######################################
13
25
 
14
- belongs_to :capital, class_name: ::KirguduRefs::Globe::City, foreign_key: :capital_id
15
- #belongs_to :image, class_name: ::ErpZone::Common::Image, foreign_key: :image_id
26
+ validates_presence_of :name, :slug, :iso2
27
+ validates_uniqueness_of :name, :slug, :iso2, case_sensitive: false, scope: :portal_id
16
28
 
17
- has_many :states, class_name: ::KirguduRefs::Globe::State, foreign_key: :country_id, dependent: :destroy
18
- has_many :regions, class_name: ::KirguduRefs::Globe::Region, foreign_key: :country_id, dependent: :destroy
19
- has_many :cities, class_name: ::KirguduRefs::Globe::City, foreign_key: :country_id, dependent: :destroy
29
+ validates_length_of :name, maximum: 128
30
+ validates_length_of :slug, maximum: 128
31
+ validate_as_seo_tag :slug, allow_nil: true
20
32
 
33
+ validates_length_of :iso2, is: 2, allow_blank: true
34
+ validates_length_of :iso3, is: 3, allow_blank: true
21
35
 
22
- validates_presence_of :name, :slug, :iso2
23
- validates_uniqueness_of :name, :slug, :iso2, case_sensitive: false
24
- validate_as_seo_tag :slug
36
+ validates_length_of :meta_keywords, maximum: 200, allow_blank: true
37
+ validates_length_of :meta_description, maximum: 200, allow_blank: true
25
38
 
39
+ validates_length_of :phone_code, maximum: 10, allow_blank: true
26
40
 
41
+ ########################################### SCOPES #########################################
27
42
 
43
+ include ::KirguduBase::Models::Scopes::WithName
44
+ include ::KirguduBase::Models::Scopes::WithSlug
28
45
 
46
+ scope :by_capital, lambda { |value| where(capital_id: value) if value }
29
47
 
30
- scope :by_currency, lambda { |value| where(currency_id: value) if value }
31
- scope :by_capital, lambda { |value| where(capital_id: value) if value }
48
+ scope :with_area_min, lambda { |value| where { area >= value } if value }
49
+ scope :with_area_max, lambda { |value| where { area <= value } if value }
50
+ scope :with_population_min, lambda { |value| where { population >= value } if value }
51
+ scope :with_population_max, lambda { |value| where { population <= value } if value }
32
52
 
33
- scope :with_area_min, lambda { |value| where{ area >= value } if value }
34
- scope :with_area_max, lambda { |value| where{ area <= value } if value }
35
- scope :with_population_min, lambda { |value| where{ population >= value } if value }
36
- scope :with_population_max, lambda { |value| where{ population <= value } if value }
53
+ scope :with_keyword, lambda { |value|
54
+ if value
55
+ value = value.gsub('%', ' ').strip
56
+ like_value ="%#{value}%"
57
+ where { (name.like like_value) | (slug.like like_value) }
58
+ end
59
+ }
37
60
 
38
- scope :with_keyword, lambda { |value|
39
- if value
40
- value = value.gsub('%', ' ').strip
41
- like_value ="%#{value}%"
42
- where { (name.like like_value) | (slug.like like_value) }
43
- end
44
- }
61
+ def self.apply_filters_to_query(query, filters={})
62
+ filters ||= {}
45
63
 
46
- def self.apply_filters_to_query(query, filters={})
47
- filters ||= {}
64
+ query = query
65
+ .with_area_min(filters[:area_min])
66
+ .with_area_max(filters[:area_max])
67
+ .with_population_min(filters[:population_min])
68
+ .with_population_max(filters[:population_max])
69
+ .by_currency(filters[:currency_id])
70
+ .by_capital(filters[:capital_id])
48
71
 
49
- query = query
50
- .with_keyword(filters[:keyword])
51
- .with_area_min(filters[:area_min])
52
- .with_area_max(filters[:area_max])
53
- .with_population_min(filters[:population_min])
54
- .with_population_max(filters[:population_max])
55
- .by_currency(filters[:currency_id])
56
- .by_capital(filters[:capital_id])
72
+ super(query, filters)
73
+ end
57
74
 
58
- super(query, filters)
59
- end
75
+ def capital_name
76
+ capital.name if capital
77
+ end
60
78
 
61
- def capital_name
62
- capital.name if capital
63
- end
79
+ private
80
+ def normalize_values_before_validation
64
81
 
82
+ self.iso2.upcase!
83
+ self.iso2.strip!
84
+ if self.iso3
85
+ self.iso3.strip!
86
+ self.iso3.upcase!
87
+ end
88
+ self.name.capitalize!
65
89
 
66
- private
67
- def normalize_values
90
+ super
91
+ end
68
92
 
69
- iso2.upcase!
70
- iso2.strip!
71
- if iso3
72
- iso3.strip!
73
- iso3.upcase!
74
- end
75
- name.capitalize!
76
- end
77
-
78
- end
79
- end
93
+ end
94
+ end
95
+ end