class TokyoMetro::Factory::YamlStationList::EachStation
駅名のリストを作成するときの各駅の情報を扱うクラス
Constants
- REGEXP_FOR_SPLIT
スラッシュ(前後に空白がある場合はそれも含む)にマッチする正規表現
Public Class Methods
new( key_of_h1 , header , contents )
click to toggle source
Constructor
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 8 def initialize( key_of_h1 , header , contents ) @key = key_of_h1 @header = header @contents = contents end
Public Instance Methods
last_index_of_station_info()
click to toggle source
駅情報の最後の index(この先は停車駅情報)
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 53 def last_index_of_station_info if @header.include?( "station_code" ) @header.index( "station_code" ) else @header.index( "name_en" ) end end
station_facility_info?()
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 18 def station_facility_info? /\Aodpt\.StationFacility\:/ === @key end
station_info?()
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 14 def station_info? /\Aodpt\.Station\:/ === @key end
to_hash_of_hash()
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 22 def to_hash_of_hash h = Hash.new @contents.each_with_index do | content , i | title = @header[ i ] border_index = self.last_index_of_station_info if i <= border_index # inspect_of_custom_alias( title , content ) h[ title ] = set_content( title , content ) else case title when "administrator" , "other_operator" h[ title ] = set_content( title , content ) else set_train_types_to_hash( h , title , content ) end end end return h end
Private Instance Methods
inspect_of_custom_alias( title , content )
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 63 def inspect_of_custom_alias( title , content ) if title == "station_facility_custom" and content == @key custom_alias = station_facility_custom_alias unless custom_alias.nil? or custom_alias == "" puts custom_alias end end end
set_content( title , content )
click to toggle source
ハッシュ (h2) の値の設定
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 73 def set_content( title , content ) if content.instance_of?( ::String ) and REGEXP_FOR_SPLIT === content return content.split( REGEXP_FOR_SPLIT ) elsif station_facility_info? and title == "station_facility_custom" and content == @key custom_alias = self.station_facility_custom_alias case custom_alias when nil , "" return nil end elsif station_info? and title == "station_facility_custom" and content == station_facility return nil elsif /Kojimachi\Z/ === content and title == "name_ja" return "麴町" end return content end
set_train_types_to_hash( h , title , content )
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 94 def set_train_types_to_hash( h , title , content ) train_types = title.split( / *\/ */ ) case content # 停車 when "○" set_train_types_to_hash__sub( h , train_types , "stop") # 一部停車 when "・" , "※" , "△" set_train_types_to_hash__sub( h , train_types , "some_trains_stop" ) # 運転停車(代々木上原) when "―" set_train_types_to_hash__sub( h , train_types , "stop_for_drivers" ) end end
set_train_types_to_hash__sub( h , ary , key )
click to toggle source
# File lib/tokyo_metro/factory/yaml_station_list/each_station.rb, line 109 def set_train_types_to_hash__sub( h , ary , key ) if h[ key ].nil? h[ key ] = ary elsif h[ key ].instance_of?( ::Array ) h[ key ] += ary end end