Class: TokyoMetro::Factory::YamlStationList

Inherits:
Object
  • Object
show all
Defined in:
lib/tokyo_metro/factory/yaml_station_list.rb

Overview

駅名のリストを作成するためのクラス(メタクラス)

Defined Under Namespace

Classes: EachStation

Class Method Summary collapse

Class Method Details

.processnil

駅名の CSV ファイルを処理し、YAML ファイルに変換するメソッド

Returns:

  • (nil)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tokyo_metro/factory/yaml_station_list.rb', line 6

def self.process
  puts "#{self.name} - Make list of stations"
  puts ""

  files = Dir.glob( "#{ ::TokyoMetro::GEM_DB_DIR }/dictionary/station/**/**.csv" )

  files.each do | file |
    header , *rows = open( file , "r:Windows-31j" ).read.encode( "UTF-8" ).split( "\n" ).map { | row | row.split( "\," ) }
    title_of_table , *header = header

    hash_of_hash = make_hash_of_hash( header , rows )
    str = make_yaml_str( hash_of_hash )

    file_generated = file.gsub( "#{ ::TokyoMetro::GEM_DB_DIR }/dictionary" , ::TokyoMetro.dictionary_dir ).gsub( /\.csv\Z/ , ".yaml" )
    File.open( file_generated , "w:utf-8" ) do | file |
      file.print( str )
    end
  end
  return nil
end