Module: TokyoMetro::Test::Api::TrainTimetable
- Defined in:
- lib/tokyo_metro/test/api/train_timetable.rb
Defined Under Namespace
Classes: TrainInfo
Class Method Summary collapse
Class Method Details
.yurakucho_and_fukutoshin_line_trains ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tokyo_metro/test/api/train_timetable.rb', line 3 def self.yurakucho_and_fukutoshin_line_trains string_ary = ::Array.new railway_lines = [ :yurakucho , :fukutoshin ] operation_days = [ [ :is_operated_on_weekdays? , "Weekday" ] , [ :is_operated_on_saturdays_and_holidays? , "Holiday" ] ] railway_lines.each do | railway_line | operation_days.each do | method_name_for_determining_operation_day , operation_day_name | = ::TokyoMetro::Api..send( railway_line ).select( &method_name_for_determining_operation_day ).sort_by( &:train_number ) = .map { | train | ::TokyoMetro::Test::Api::TrainTimetable::TrainInfo.new( train ) } # 行先などの基本情報でグループ化 h = .group_by( &:output ) # ヘッダーの出力 make_header( string_ary , "#{ railway_line.to_s.capitalize } #{ operation_day_name }" ) h.each.with_index(1) do | ( output , trains ) , i | string_ary << [ "Pattern number" , "#{ title } #{i}" ].join( "," * 4 ) string_ary << output.split( "\n" ).map { | str | str = str.gsub( /\A([\w ]+)\:/ ) { "#{ $1 }" + "," * 4 } str = str.gsub( "元町・中華街" , "元町中華街" ) str = str.gsub( /(/ ) { ",(" } str }.join( "\n" ) string_ary << [ "Trains" , trains.length.to_s ].join( "," * 4 ) string_ary << "" string_ary << trains.map( &:train_number ).each_slice(10).to_a.map { | group | group.join( "," ) } string_ary << "" end end end str = string_ary.flatten.join( "\n" ).gsub( /[ \n]+\Z/ , "" ).encode( "windows-31j" ) ::File.open( "#{ ::TokyoMetro::DEV_DIR }/document/result/yurakucho_and_fukutoshin_line.csv" , "w:windows-31j" ) do |f| f.print( str ) end end |