Module: CountryStateSelect
- Defined in:
- lib/country_state_select/engine.rb,
lib/country_state_select.rb,
lib/country_state_select/engine3.rb,
lib/country_state_select/railtie.rb,
lib/country_state_select/version.rb,
app/controllers/country_state_select/cscs_controller.rb
Overview
Defined Under Namespace
Modules: Rails Classes: CscsController
Constant Summary collapse
- VERSION =
"3.0.3"
Class Method Summary collapse
-
.cities_collection(f, options) ⇒ Object
Return either the City (String) or Cities (Array).
-
.city_options(options) ⇒ Object
Return a hash for use in the simple_form.
-
.collect_cities(state_id = '', country_id = '') ⇒ Object
Return the cities of given state and country.
-
.collect_states(country) ⇒ Object
Return the collected States for a given Country.
-
.countries_collection ⇒ Object
Collect the Countries.
-
.countries_except(*except) ⇒ Object
Pass array of unwanted countries to get back all except those in the array.
-
.merge_hash(options, collections) ⇒ Object
Create hash to use in the simple_form.
-
.state_options(options) ⇒ Object
Return a hash for use in the simple_form.
-
.states_collection(f, options) ⇒ Object
Return either the State (String) or States (Array).
Class Method Details
.cities_collection(f, options) ⇒ Object
Return either the City (String) or Cities (Array)
25 26 27 28 |
# File 'lib/country_state_select.rb', line 25 def self.cities_collection(f, ) cities = collect_cities(f.object.send([:state])) cities end |
.city_options(options) ⇒ Object
Return a hash for use in the simple_form
52 53 54 55 |
# File 'lib/country_state_select.rb', line 52 def self.() cities = cities_collection([:form], [:field_names]) = self.merge_hash(, cities) end |
.collect_cities(state_id = '', country_id = '') ⇒ Object
Return the cities of given state and country
37 38 39 40 41 42 43 |
# File 'lib/country_state_select.rb', line 37 def self.collect_cities(state_id = '', country_id = '') if state_id.nil? || country_id.nil? [] else CS.cities(state_id.to_sym, country_id.to_sym) end end |
.collect_states(country) ⇒ Object
Return the collected States for a given Country
32 33 34 |
# File 'lib/country_state_select.rb', line 32 def self.collect_states(country) CS.states(country).collect {|p| [ p[1], p[0] ] }.compact end |
.countries_collection ⇒ Object
Collect the Countries
8 9 10 |
# File 'lib/country_state_select.rb', line 8 def self.countries_collection CS.countries.except!(:COUNTRY_ISO_CODE).collect {|p| [ p[ 1], p[0] ] }.compact end |
.countries_except(*except) ⇒ Object
Pass array of unwanted countries to get back all except those in the array
13 14 15 |
# File 'lib/country_state_select.rb', line 13 def self.countries_except(*except) countries_collection.collect { |c| c unless except.include?(c[1]) }.compact end |
.merge_hash(options, collections) ⇒ Object
Create hash to use in the simple_form
58 59 60 61 62 |
# File 'lib/country_state_select.rb', line 58 def self.merge_hash(, collections) = .merge(collection: collections) = .merge(:as => :string) if collections.class == String end |
.state_options(options) ⇒ Object
Return a hash for use in the simple_form
46 47 48 49 |
# File 'lib/country_state_select.rb', line 46 def self.() states = states_collection([:form], [:field_names]) = self.merge_hash(, states) end |
.states_collection(f, options) ⇒ Object
Return either the State (String) or States (Array)
18 19 20 21 22 |
# File 'lib/country_state_select.rb', line 18 def self.states_collection(f, ) states = collect_states(f.object.send([:country])) return f.object.send([:state]) if states.size == 0 states end |