Class: TokyoMetro::Api::RailwayLine

Inherits:
MetaClass::Hybrid show all
Includes:
ClassNameLibrary::Api::RailwayLine
Defined in:
lib/tokyo_metro/api/railway_line.rb

Overview

Note:

路線情報 odpt:Railwayは、鉄道路線の情報を示す。 運行系統名、駅間所要時間、駅間順序などを加筆・修正したものとなる。

路線情報 odpt:Railway を扱うクラス

Defined Under Namespace

Classes: Info, List

クラスメソッド - データの取得・保存 collapse

テスト・開発 collapse

Methods inherited from MetaClass::Fundamental

factory_for_generating_from_saved_file

Class Method Details

.get(http_client, id_urn: nil, same_as: nil, title: nil, operator: nil, railway_line_code: nil, parse_json: false, generate_instance: false, to_inspect: false) ⇒ ::Array

Note:

固有識別子 id は、支線には別IDを割り当てる。

路線情報を取得するメソッド

Parameters:

  • http_client (HTTPClient)

    HTTPClient のインスタンス【必須】

  • id_urn (String) (defaults to: nil)

    固有識別子 (ucode) <id - URN>

  • same_as (String) (defaults to: nil)

    固有識別子(命名ルールは「odpt.Railway:TokyoMetro.路線名」) <owl:sameAs - URL>

  • title (String) (defaults to: nil)

    運行系統名 <dc:title - xsd:string>

  • operator (String) (defaults to: nil)

    運行会社 <odpt:operator - odpt:Operator>

  • railway_line_code (String) (defaults to: nil)

    路線コード <odpt:lineCode - xsd:string>

  • parse_json (Boolean) (defaults to: false)

    JSONを配列とするか否かの設定(false の場合は文字列とする)

  • generate_instance (Boolean) (defaults to: false)

    データ取得後に Ruby のインスタンスを作成するか否かの設定

  • to_inspect (Boolean) (defaults to: false)

    データ取得後にコマンドツールに内容を表示するか否かの設定

Returns:

  • (::Array)


22
23
24
25
26
27
28
# File 'lib/tokyo_metro/api/railway_line.rb', line 22

def self.get( http_client ,
  id_urn: nil , same_as: nil , title: nil , operator: nil , railway_line_code: nil ,
  parse_json: false , generate_instance: false , to_inspect: false )

  factory_for_getting.process( http_client , id_urn , same_as , title , operator , railway_line_code ,
    parse_json , generate_instance , to_inspect )
end

.get_geo_test(http_client, geo_long, geo_lat, radius) ⇒ nil

データ取得のテスト

Returns:

  • (nil)


98
99
100
101
102
103
104
105
106
# File 'lib/tokyo_metro/api/railway_line.rb', line 98

def self.get_geo_test( http_client , geo_long , geo_lat , radius )
  puts "#{get_test_title} (geo)"
  result = get_geo( http_client , geo_long , geo_lat , radius , to_inspect: true , parse_json: true , generate_instance: true )
  puts "(#{result.length})"
  result.sort_by( &:operator ).each do | rail |
    puts rail.to_strf
    puts "" * 2
  end
end

.get_station_order_for_each_line(http_client) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/tokyo_metro/api/railway_line.rb', line 75

def self.get_station_order_for_each_line( http_client )
  ary = get( http_client , to_inspect: true , parse_json: true , generate_instance: true ).sort_by_railway_line_order

  dirname_str = "#{db_dirname}/for_development"
  ::FileUtils.mkdir_p( dirname_str )
  Dir.chdir( dirname_str )

  ary.each do | railway_line |
    file = File.open( "TokyoMetro_#{railway_line.railway_line_code_for_filename}.txt" , "w:utf-8" )
    railway_line.station_order.each do | station_info |
      station_facility_info = station_info.name.gsub( "odpt\.Station\:" , "odpt\.StationFacility\:" ).gsub( /\.[a-zA-Z]+\.([a-zA-Z]+)\Z/ ) { | matched | "\.#{$1}" }

      file.print station_info.name
      file.print "\t"
      file.print station_facility_info
      file.print "\n"
    end
    file.close
  end
end

.get_test(http_client, railway_line) ⇒ nil

データ取得のテスト

Parameters:

  • http_client (HTTPClient)
  • railway_line (String)

    路線(“xxxx.yyyy” を指定すると、“odpt.Railway:xxxx.yyyy” の駅情報を呼び出す)

Returns:

  • (nil)


58
59
60
61
62
63
64
65
66
# File 'lib/tokyo_metro/api/railway_line.rb', line 58

def self.get_test( http_client , railway_line )
  unless /\Aodpt\.Railway\:/ === railway_line
    railway_line = "odpt.Railway:#{railway_line}"
  end
  puts "#{get_test_title}"
  ary = get( http_client , same_as: railway_line , to_inspect: true , parse_json: true , generate_instance: true )
  puts "#{railway_line} (#{ary.length})"
  puts ary.sort_by_railway_line_order.to_strf
end

.get_test_for_each_line(http_client) ⇒ Object



68
69
70
71
72
73
# File 'lib/tokyo_metro/api/railway_line.rb', line 68

def self.get_test_for_each_line( http_client )
  ::TokyoMetro::Static.railway_lines_operated_by_tokyo_metro.each do | line |
    self.get_test( http_client , line )
    sleep( 2 )
  end
end

.save(http_client, filename, file_type: :yaml, id_urn: nil, same_as: nil, title: nil, operator: nil, railway_line_code: nil, to_inspect: true) ⇒ nil

路線情報を取得し保存するメソッド

Parameters:

  • http_client (HTTPClient)

    HTTPClient のインスタンス【必須】

  • id_urn (String) (defaults to: nil)

    固有識別子 (ucode) <id - URN>

  • same_as (String) (defaults to: nil)

    固有識別子(命名ルールは「odpt.Railway:TokyoMetro.路線名」) <owl:sameAs - URL>

  • title (String) (defaults to: nil)

    運行系統名 <dc:title - xsd:string>

  • operator (String) (defaults to: nil)

    運行会社 <odpt:operator - odpt:Operator>

  • railway_line_code (String) (defaults to: nil)

    路線コード <odpt:lineCode - xsd:string>

  • to_inspect (Boolean) (defaults to: true)

    データ取得後にコマンドツールに内容を表示するか否かの設定

Returns:

  • (nil)


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tokyo_metro/api/railway_line.rb', line 39

def self.save( http_client , filename , file_type: :yaml ,
  id_urn: nil , same_as: nil , title: nil , operator: nil , railway_line_code: nil ,
  to_inspect: true )

  data = get( http_client ,
    id_urn: id_urn , same_as: same_as , title: title , operator: operator , railway_line_code: railway_line_code ,
    parse_json: true , generate_instance: false , to_inspect: to_inspect )

  # data = eval( data.to_s.gsub( /(?:\r\n|\r)/ ,"\n" ).encode( "UTF-8" ) )

  save_data( data , filename , file_type: file_type )
end