Module: TokyoMetro

Defined in:
lib/tokyo_metro.rb,
lib/tokyo_metro/version.rb

Overview

東京メトロ オープンデータを扱うモジュール

Defined Under Namespace

Modules: Api, ApiProcessor, App, ClassNameLibrary, Dictionary, Document, Factory, Initializer, Modules, Rake, Refinement, Search, Static, TempLib, Test Classes: Required

API へのアクセス collapse

API_ENDPOINT =

東京メトロオープンデータ API のエンドポイント

"https://api.tokyometroapp.jp/api/v2"
DATAPOINTS_URL =

データ取得・検索 API

"#{API_ENDPOINT}/datapoints"
PLACES_URL =

地物情報取得・検索 API

"#{API_ENDPOINT}/places"

駅名辞書 collapse

STATION_DICTIONARY =
::YAML.load_file( "#{ DICTIONARY_DIR }/station/tokyo_metro.yaml" )

時刻 collapse

DATE_CHANGING_HOUR =

ダイヤ上の日付変更時刻

3
DEFAULT_TIME_ZONE =
::Kernel.Rational(9,24)

Constant Summary collapse

LIB_DIR =
::File.expand_path( ::File.dirname( __FILE__ ) )
TOP_DIR =
Note:

“#{ ::Rails.root }” とはしない

Gem のトップディレクトリ

::File.expand_path( "#{ LIB_DIR }/.." )
DICTIONARY_DIR =

辞書ファイルのディレクトリ

::File.expand_path( "#{ LIB_DIR }/tokyo_metro/dictionary" )
VERSION =
::File.open( "#{ ::File.dirname( __FILE__ ) }/../../.current_version" , "r:utf-8" ).read.chomp

駅名辞書 collapse

時刻 collapse

モジュールの組み込み collapse

定数 collapse

関連ファイルのロード collapse

GoogleMaps collapse

Rails 関連 collapse

運行日に関するメソッド collapse

運行ダイヤに関するメソッド collapse

Class Method Details

.current_diagramObject



185
186
187
# File 'lib/tokyo_metro.rb', line 185

def self.current_diagram
  diagram_as_of( current_operation_day )
end

.current_operation_dayObject



170
171
172
# File 'lib/tokyo_metro.rb', line 170

def self.current_operation_day
  ::TokyoMetro::Static::OperationDay.of_current
end

.diagram_as_of(time) ⇒ Object



180
181
182
183
# File 'lib/tokyo_metro.rb', line 180

def self.diagram_as_of( time )
  t = operation_day_as_of( time )
  ::TokyoMetro::Modules::Db::Select::OperationDay.process(t)
end

.google_maps_javasciprt_uriObject



158
159
160
# File 'lib/tokyo_metro.rb', line 158

def self.google_maps_javasciprt_uri
  "https://maps.googleapis.com/maps/api/js?key=#{ GOOGLE_MAPS_API_KEY }&sensor=true"
end

.initialize_in_local_environment(rails_dir) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/tokyo_metro.rb', line 146

def self.initialize_in_local_environment( rails_dir )
  set_rails_consts( rails_dir )
  set_modules
  set_fundamental_constants

  set_access_token
  set_google_maps_api_key
end

.method_missing(method_name, *args) ⇒ Object



192
193
194
195
196
197
198
199
200
201
# File 'lib/tokyo_metro.rb', line 192

def method_missing( method_name , *args )
  if /const/ === method_name.to_s
    valid_method_name = method_name.to_s.gsub( "const" , "constant" )
    if methods.map( &:to_s ).include?( valid_method_name )
      return send( valid_method_name , *args )
    end
  end

  super( method_name , *args )
end

.operation_day_as_of(time) ⇒ Object



174
175
176
# File 'lib/tokyo_metro.rb', line 174

def self.operation_day_as_of( time )
  ::TokyoMetro::Static::OperationDay.as_of( time )
end

.reload_all_files!Object



133
134
135
136
137
# File 'lib/tokyo_metro.rb', line 133

def self.reload_all_files!
  open( "#{ TOP_DIR }/required_files.txt" , "r:utf-8" ).read.split( /\n/ ).each do |f|
    load "#{ ::Rails.root }/#{ f }"
  end
end

.require_files(settings: nil, file_type: "txt") ⇒ Object



139
140
141
142
143
144
# File 'lib/tokyo_metro.rb', line 139

def self.require_files( settings: nil , file_type: "txt" )
  settings ||= :make_list_of_required_files
  required_files( settings , file_type ).each do | filename |
    require filename
  end
end

.set_all_api_constantsObject



123
124
125
# File 'lib/tokyo_metro.rb', line 123

def self.set_all_api_constants
  set_api_constants( config_of_api_constants_when_load_all )
end

.set_all_api_constants_without_fareObject



127
128
129
# File 'lib/tokyo_metro.rb', line 127

def self.set_all_api_constants_without_fare
  set_api_constants( config_of_api_constants_when_load_without_fare )
end

.set_api_constants(config_of_api_constants = nil) ⇒ Object



119
120
121
# File 'lib/tokyo_metro.rb', line 119

def self.set_api_constants( config_of_api_constants = nil )
  ::TokyoMetro::Api::set_constants( config_of_api_constants )
end

.set_constants(config_of_api_constants = nil) ⇒ Object



114
115
116
117
# File 'lib/tokyo_metro.rb', line 114

def self.set_constants( config_of_api_constants = nil )
  set_fundamental_constants
  set_api_constants( config_of_api_constants )
end

.set_fundamental_constantsObject

定数の定義



109
110
111
112
# File 'lib/tokyo_metro.rb', line 109

def self.set_fundamental_constants
  ::TokyoMetro::Static::set_constants
  ::TokyoMetro::Api.set_constants_for_timetable
end

.set_modulesObject



101
102
103
# File 'lib/tokyo_metro.rb', line 101

def self.set_modules
  ::TokyoMetro::Initializer::Modules.set
end

.set_rails_consts(rails_dir = ::Rails.root.to_s) ⇒ Object



164
165
166
# File 'lib/tokyo_metro.rb', line 164

def self.set_rails_consts( rails_dir = ::Rails.root.to_s )
  ::TokyoMetro::Initializer::Rails.consts_in_gem.set( as_for: rails_dir )
end

.station_dictionary_including_main_info(stations_of_railway_lines = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tokyo_metro.rb', line 62

def self.station_dictionary_including_main_info( stations_of_railway_lines = nil )
  if stations_of_railway_lines.nil?
    stations_of_railway_lines = ::Station::Info.where( operator_id: ::Operator.id_of_tokyo_metro )
  end

  h = ::Hash.new

  station_dictionary.each do | name_in_system , name_ja |
    stations_in_db = stations_of_railway_lines.where( name_in_system: name_in_system )
    name_h = {
      :name_ja => stations_in_db.first.name_ja ,
      :name_hira => stations_in_db.first.name_hira ,
      :name_en => stations_in_db.first.name_en ,
      :name_in_system => name_in_system ,
      :station_codes => stations_in_db.pluck( :station_code )
    }
    h[ name_in_system ] = name_h
  end

  return h
end

.time_now(time_zone: nil) ⇒ DateTime

Note:

タイムゾーンは日本時間 (GMT+9)

現在時刻

Returns:

  • (DateTime)


94
95
96
97
# File 'lib/tokyo_metro.rb', line 94

def self.time_now( time_zone: nil )
  rational_for_time_zone ||= DEFAULT_TIME_ZONE
  ::DateTime.now.new_offset( rational_for_time_zone )
end