Module: Pilgrim::Methods::InstanceMethods

Defined in:
lib/pilgrim/load_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_cities(state_id) ⇒ Object



18
19
20
21
# File 'lib/pilgrim/load_methods.rb', line 18

def get_cities(state_id)
	state = Pilgrim::State.find(state_id)
	state.cities
end

#get_countries(mode = "all", arr_countries = []) ⇒ Object



8
9
10
11
# File 'lib/pilgrim/load_methods.rb', line 8

def get_countries(mode = "all", arr_countries = [])
	countries = Pilgrim::Country.get_countries(mode, arr_countries)
	return countries
end

#get_locations(options = {}) ⇒ Object

def get_locations(country_id = 0, state_id = 0, city_id = 0)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pilgrim/load_methods.rb', line 24

def get_locations(options = {})
	country_id = options.has_key?(:country_id) ? options[:country_id] : 0
	state_id = options.has_key?(:state_id) ? options[:state_id] : 0
	city_id = options.has_key?(:city_id) ? options[:city_id] : 0
	mode = options.has_key?(:mode) ? options[:mode] : "all"
	arr_countries = options.has_key?(:countries) ? options[:countries] : []

tmp_countries = get_countries(mode, arr_countries)

country_id = tmp_countries.first.id if country_id == 0
countries = transform_result(tmp_countries, country_id)
tmp_states = get_states(country_id)

state_id = tmp_states.first.id if state_id == 0 and !tmp_states.empty?
states = transform_result(tmp_states, state_id)
tmp_cities = get_cities(state_id)

city_id = tmp_cities.first.id if city_id == 0 and !tmp_cities.empty?
cities = transform_result(tmp_cities, city_id)

{
	countries: countries,
	states: states,
	cities: cities
}
end

#get_states(country_id) ⇒ Object



13
14
15
16
# File 'lib/pilgrim/load_methods.rb', line 13

def get_states(country_id)
	country = Pilgrim::Country.find(country_id)
	country.states
end

#transform_result(data, selected) ⇒ Object



51
52
53
# File 'lib/pilgrim/load_methods.rb', line 51

def transform_result(data, selected)
	{data: data, selected: selected}
end