Class: MockCity
- Inherits:
-
Object
- Object
- MockCity
- Defined in:
- lib/mock_city.rb
Constant Summary collapse
- CITIES =
YAML.load(File.open("features/data/sites.yml"))
Instance Attribute Summary collapse
-
#name_lang ⇒ Object
readonly
Returns the value of attribute name_lang.
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
#initialize(*args) ⇒ MockCity
site,code=nil)
9 10 11 12 13 14 15 16 |
# File 'lib/mock_city.rb', line 9 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"] @name_lang = city["name_lang"] end |
Instance Attribute Details
#name_lang ⇒ Object (readonly)
Returns the value of attribute name_lang.
7 8 9 |
# File 'lib/mock_city.rb', line 7 def name_lang @name_lang end |
Instance Method Details
#add_airport(airport) ⇒ Object
34 35 36 |
# File 'lib/mock_city.rb', line 34 def add_airport(airport) @airports << airport end |
#airports ⇒ Object
22 23 24 |
# File 'lib/mock_city.rb', line 22 def airports() @airports end |
#code ⇒ Object
18 19 20 |
# File 'lib/mock_city.rb', line 18 def code() @code end |
#find_city(code) ⇒ Object
38 39 40 41 42 |
# File 'lib/mock_city.rb', line 38 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
55 56 57 58 59 |
# File 'lib/mock_city.rb', line 55 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["code"])}} return MockCity.new(@site,arr_tmp[rand(arr_tmp.length)]["code"]) end |
#generate_to_city(cabotage, black_list = []) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mock_city.rb', line 44 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
26 27 28 29 30 31 32 |
# File 'lib/mock_city.rb', line 26 def name(site=nil) if site @name.split('|').length==1 ? @name.split('|').first : @name.split('|')[site=="BR" ? 1 : 0] else return @name end end |