Class: TokyoMetro::Api::Station

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

Overview

Note:

駅情報 odpt:Stationは、駅の情報を示す。この情報は国土交通省国土数値情報を元に、 施設情報や乗り換え路線などを加筆・修正したものとなる。

駅情報 odpt:Station を扱うクラス

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: nil, station_code: nil, parse_json: false, generate_instance: false, to_inspect: false) ⇒ ::Array

駅情報を取得するメソッド

Parameters:

  • http_client (HTTPClient)

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

  • id_urn (String) (defaults to: nil)

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

  • same_as (String) (defaults to: nil)

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

  • title (String) (defaults to: nil)

    駅名 <dc:title - xsd:string>

  • operator (String) (defaults to: nil)

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

  • railway_line (String) (defaults to: nil)

    路線 <odpt:railway - odpt:Railway>

  • station_code (String) (defaults to: nil)

    駅コード <odpt:stationCode - 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/station.rb', line 22

def self.get( http_client ,
  id_urn: nil , same_as: nil , title: nil , operator: nil , railway_line: nil , station_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 , station_code ,
    parse_json , generate_instance , to_inspect )
end

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

データ取得のテスト

Returns:

  • (nil)


70
71
72
73
74
75
76
77
78
# File 'lib/tokyo_metro/api/station.rb', line 70

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( &:same_as ).each do | rail |
    puts rail.to_strf
    puts "" * 2
  end
end

.get_test(http_client, station) ⇒ nil

データ取得のテスト

Parameters:

  • http_client (HTTPClient)
  • station (String)

    駅名(“xxxx.yyyy.zzzz” を指定すると、“odpt.Station:xxxx.yyyy.zzzz” の駅情報を呼び出す)

Returns:

  • (nil)


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

def self.get_test( http_client , station )
  station = "odpt.Station:#{station}"
  puts "#{get_test_title}"
  ary = get( http_client , same_as: station , to_inspect: true , parse_json: true , generate_instance: true )
  puts "#{station} (#{ary.length})"
  puts ary.first.to_strf
end

.save(http_client, filename, file_type: :yaml, id_urn: nil, same_as: nil, title: nil, operator: nil, railway_line: nil, station_code: nil, to_inspect: false) ⇒ nil

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

Parameters:

  • http_client (HTTPClient)

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

  • file_type (Symbol) (defaults to: :yaml)

    保存するファイルの種類【必須】

  • id_urn (String) (defaults to: nil)

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

  • same_as (String) (defaults to: nil)

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

  • title (String) (defaults to: nil)

    駅名 <dc:title - xsd:string>

  • operator (String) (defaults to: nil)

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

  • railway_line (String) (defaults to: nil)

    路線 <odpt:railway - odpt:Railway>

  • station_code (String) (defaults to: nil)

    駅コード <odpt:stationCode - xsd:string>

  • to_inspect (Boolean) (defaults to: false)

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

Returns:

  • (nil)


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tokyo_metro/api/station.rb', line 41

def self.save( http_client , filename , file_type: :yaml ,
  id_urn: nil , same_as: nil , title: nil , operator: nil , railway_line: nil , station_code: nil ,
  to_inspect: false )

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

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

  save_data( data , filename , file_type: file_type )
end