module CountryStateSelect
@author Sachin Singh
@author Sachin Singh
@author Sachin Singh
Constants
- VERSION
Public Class Methods
cities_collection(f, options)
click to toggle source
Return either the City (String) or Cities (Array)
# File lib/country_state_select.rb, line 27 def self.cities_collection(f, options) cities = collect_cities(f.object.send(options[:state])) end
city_options(options)
click to toggle source
Return a hash for use in the simple_form
# File lib/country_state_select.rb, line 50 def self.city_options(options) cities = cities_collection(options[:form], options[:field_names]) options = merge_hash(options, cities) end
collect_cities(state_id = '', country_id = '')
click to toggle source
Return the cities of given state and country
# File lib/country_state_select.rb, line 37 def self.collect_cities(state_id = '', country_id = '') return [] if state_id.nil? || country_id.nil? CS.cities(state_id.to_sym, country_id.to_sym) end
collect_states(country)
click to toggle source
Return the collected States for a given Country
# 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()
click to toggle source
Collect the Countries
# File lib/country_state_select.rb, line 9 def self.countries_collection CS.countries.except!(:COUNTRY_ISO_CODE).collect { |p| [p[1], p[0]] }.compact end
countries_except(*except)
click to toggle source
Pass array of unwanted countries to get back all except those in the array
# File lib/country_state_select.rb, line 14 def self.countries_except(*except) countries_collection.collect { |c| c unless except.include?(c[1]) }.compact end
merge_hash(options, collections)
click to toggle source
Create hash to use in the simple_form
# File lib/country_state_select.rb, line 56 def self.merge_hash(options, collections) options = options.merge(collection: collections) options = options.merge(as: :string) if collections.instance_of?(String) options end
state_options(options)
click to toggle source
Return a hash for use in the simple_form
# File lib/country_state_select.rb, line 44 def self.state_options(options) states = states_collection(options[:form], options[:field_names]) options = merge_hash(options, states) end
states_collection(f, options)
click to toggle source
Return either the State (String) or States (Array)
# File lib/country_state_select.rb, line 19 def self.states_collection(f, options) states = collect_states(f.object.send(options[:country])) return f.object.send(options[:state]) if states.empty? states end