Class: MockCity
- Inherits:
-
Object
- Object
- MockCity
- Defined in:
- lib/mock_city.rb
Constant Summary collapse
- CITIES =
YAML.load(File.open("sites.yml"))
Instance Method Summary collapse
- #add_airport(airport) ⇒ Object
- #airports ⇒ Object
- #code ⇒ Object
- #find_city(code) ⇒ Object
- #generate_city(black_list = []) ⇒ Object
- #generate_to_city(cabotage, black_list = []) ⇒ Object
-
#initialize(*args) ⇒ MockCity
constructor
site,code=nil).
- #name(site = nil) ⇒ Object
Constructor Details
Instance Method Details
#add_airport(airport) ⇒ Object
31 32 33 |
# File 'lib/mock_city.rb', line 31 def add_airport(airport) @airports << airport end |
#airports ⇒ Object
19 20 21 |
# File 'lib/mock_city.rb', line 19 def airports() @airports end |
#code ⇒ Object
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 |