Class: MockCity

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

Constant Summary collapse

CITIES =
YAML.load(File.open("sites.yml"))

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MockCity

site,code=nil)



7
8
9
10
11
12
13
# File 'lib/mock_city.rb', line 7

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



31
32
33
# File 'lib/mock_city.rb', line 31

def add_airport(airport)
	@airports << airport
end

#airportsObject



19
20
21
# File 'lib/mock_city.rb', line 19

def airports()
	@airports
end

#codeObject



15
16
17
# File 'lib/mock_city.rb', line 15

def code()
	@code
end

#find_city(code) ⇒ Object



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

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

#generate_city(black_list = []) ⇒ Object



52
53
54
55
56
# File 'lib/mock_city.rb', line 52

def generate_city(black_list=[])
	arr_tmp = Array.new
   	CITIES.reject{|key,value| key==@site}.values.collect{|cities| cities.each{|city| arr_tmp << city unless black_list.include?(city)}}
   	return MockCity.new(@site,arr_tmp[rand(arr_tmp.length)]["code"])
end

#generate_to_city(cabotage, black_list = []) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/mock_city.rb', line 41

def generate_to_city(cabotage,black_list=[])
	arr_tmp = Array.new
   	CITIES.reject{|key,value| key==@site}.values.collect{|cities| cities.each{|city| arr_tmp << city unless black_list.include?(city["code"])}}
    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



23
24
25
26
27
28
29
# File 'lib/mock_city.rb', line 23

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