Class: MockCity

Inherits:
Object
  • Object
show all
Defined in:
lib/mock_city.rb

Constant Summary collapse

CITIES =
{  'CL' => [{:code=>"SCL",:airports=>["SCL"],:name=>"Santiago de Chile|Santiago"},{:code=>"IQQ",:airports=>["IQQ"],:name=>"Iquique"}],
'AR' => [{:code=>"BUE",:airports=>["EZE","AEP","BUE"],:name=>"Buenos Aires"},{:code=>"COR",:airports=>["COR"],:name=>"Cordoba"}],
'BR' => [{:code=>"SAO",:airports=>["SAO","GRU","CGH","VCP","CPQ"],:name=>"San Pablo|Sao Paulo"},{:code=>"RIO",:airports=>["RIO","SDU","GIG"],:name=>"Rio de Janeiro"},{:code=>"FLN",:airports=>["FLN"],:name=>"Florianopolis"}],
'MX' => [{:code=>"MEX",:airports=>["MEX","TLC"],:name=>"Ciudad de Mexico|Cidade do Mexico"},{:code=>"GDL",:airports=>["GDL"],:name=>"Guadalajara"},{:code=>"CUN",:airports=>["CUN"],:name=>"Cancun"}],
'PE' => [{:code=>"LIM",:airports=>["LIM"],:name=>"Lima"}],
'VE' => [{:code=>"CCS",:airports=>["CCS"],:name=>"Caracas"}],
'CO' => [{:code=>"BOG",:airports=>["BOG"],:name=>"Bogota"},{:code=>"MDE",:airports=>["MDE"],:name=>"Medellin"},{:code=>"CLO",:airports=>["CLO"],:name=>"Cali"}],
'CR' => [{:code=>"SJO",:airports=>["SJO"],:name=>"San Jose|Sao Jose"}],
'PA' => [{:code=>"PTY",:airports=>["PTY"],:name=>"Panama|Cidade do Panama"}],
'UY' => [{:code=>"MVD",:airports=>["MVD"],:name=>"Montevideo|Montevideu"}],
'EC' => [{:code=>"UIO",:airports=>["UIO"],:name=>"Quito"},{:code=>"GYE",:airports=>["GYE"],:name=>"Guayaquil|Guaiaquil"}],
'US' => [{:code=>"MIA",:airports=>["MIA"],:name=>"Miami"},{:code=>"NYC",:airports=>["EWR","JFK","LGA","NYC"],:name=>"Nueva York|Nova York"},{:code=>"WAS",:airports=>["WAS","DCA","BWI","IAD"],:name=>"Washington"}]}

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MockCity

site,code=nil)



17
18
19
20
21
22
23
# File 'lib/mock_city.rb', line 17

def initialize(*args)#site,code=nil)
	@site = args[0]
	city = args[1] ? self.find_city(args[1]) : CITIES[@site][0]
	@code = city[:code]
	@airports = city[:airports]
	@name = city[:name]
end

Instance Method Details

#add_airport(airport) ⇒ Object



41
42
43
# File 'lib/mock_city.rb', line 41

def add_airport(airport)
	@airports << airport
end

#airportsObject



29
30
31
# File 'lib/mock_city.rb', line 29

def airports()
	@airports
end

#codeObject



25
26
27
# File 'lib/mock_city.rb', line 25

def code()
	@code
end

#find_city(code) ⇒ Object



45
46
47
48
49
# File 'lib/mock_city.rb', line 45

def find_city(code)
	city = nil
	CITIES.each_pair{|key,value| value.each{|_city| city = _city if _city[:code] == code}}
	return city
end

#generate_to_city(cabotage) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/mock_city.rb', line 51

def generate_to_city(cabotage)
	arr_tmp = Array.new
   	CITIES.reject{|key,value| key==@site}.values.collect{|cities| cities.each{|city| arr_tmp << city}}
    if CITIES[@site][1] and cabotage
      to_city = MockCity.new(@site,CITIES[@site][1][:code])
    else
      to_city = MockCity.new(@site,arr_tmp[rand(arr_tmp.length)][:code])
    end
    return to_city
end

#name(site = nil) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/mock_city.rb', line 33

def name(site=nil)
	if site
		@name.split('|').length==1 ? @name.split('|').first : @name.split('|')[site=="BR" ? 1 : 0]
	else
		return @name
	end	
end