module TokyoMetro::Api

東京メトロ オープンデータの API から提供される情報を扱うモジュール

Public Class Methods

barrier_free_facilities() click to toggle source
# File lib/tokyo_metro/api.rb, line 30
def self.barrier_free_facilities
  STATION_FACILITY.send( __method__ )
end
factory_for_getting() click to toggle source
# File lib/tokyo_metro/api.rb, line 153
def self.factory_for_getting
  ::TokyoMetro::Factory::Get::Api::DataSearch
end
factory_for_getting_geo() click to toggle source
# File lib/tokyo_metro/api.rb, line 157
def self.factory_for_getting_geo
  ::TokyoMetro::Factory::Get::Api::Geo
end
get( http_client , id_urn , parse_json: false , generate_instance: false , to_inspect: false ) click to toggle source
# File lib/tokyo_metro/api.rb, line 145
def self.get( http_client , id_urn , parse_json: false , generate_instance: false , to_inspect: false )
  factory_for_getting.process( http_client , id_urn , parse_json , generate_instance , to_inspect )
end
get_geo( http_client , id_urn , parse_json: false , generate_instance: false , to_inspect: false ) click to toggle source
# File lib/tokyo_metro/api.rb, line 149
def self.get_geo( http_client , id_urn , parse_json: false , generate_instance: false , to_inspect: false )
  factory_for_getting_geo.process( http_client , id_urn , parse_json , generate_instance , to_inspect )
end
list_of_constants() click to toggle source
# File lib/tokyo_metro/api.rb, line 10
def self.list_of_constants
  [ :station_facility , :passenger_survey , :station , :railway_line , :point , :fare , :station_timetable , :train_timetable ]
end
method_missing( method_name , *args ) click to toggle source
Calls superclass method
# File lib/tokyo_metro/api.rb, line 36
def method_missing( method_name , *args )
  if costants_converted_by_method_missing.include?( method_name.singularize.upcase )
    return const_get( method_name.singularize.upcase )
  else
    super( method_name , *args )
  end
end
set_constants( *configs_of_api_constants ) click to toggle source

東京メトロ オープンデータに関する定数を定義するメソッド (2) - API から取得し保存したデータからインスタンスを作成し、定数とする @return [nil]

# File lib/tokyo_metro/api.rb, line 16
def self.set_constants( *configs_of_api_constants )
  config_of_api_constants = set_config_of_api_constants( *configs_of_api_constants )

  if config_of_api_constants.present?
    list_of_constants.each do | symbol |
      if config_of_api_constants[ symbol ]
        set_constant( symbol )
      end
    end
  end

  return nil
end
set_constants_for_timetable() click to toggle source

東京メトロ オープンデータに関する定数を定義するメソッド (1) - 時刻表の列車の補足情報に関する定数 @return [nil]

# File lib/tokyo_metro/api.rb, line 129
def self.set_constants_for_timetable
  #---- 時刻表 到着ホーム
  ::TokyoMetro::Api::StationTimetable::Info::TrainTime::Info::Note::ArriveAt::set_constants

  #---- 時刻表 出発ホーム
  ::TokyoMetro::Api::StationTimetable::Info::TrainTime::Info::Note::PlatformNumber::set_constant
end
station_train_time() click to toggle source
# File lib/tokyo_metro/api.rb, line 6
def self.station_train_time
  ::TokyoMetro::Api::StationTrainTime
end
timetable_notes_of_arrival_at_asakusa() click to toggle source
# File lib/tokyo_metro/api.rb, line 137
def self.timetable_notes_of_arrival_at_asakusa
  ::TokyoMetro::Api::StationTimetable::Info::TrainTime::Info::Note::ArriveAt::ASAKUSA
end
timetable_notes_of_departure() click to toggle source
# File lib/tokyo_metro/api.rb, line 141
def self.timetable_notes_of_departure
  ::TokyoMetro::Api::StationTimetable::Info::TrainTime::Info::Note::PlatformNumber::LIST
end

Private Class Methods

numbers_of_constants( ary_for_display ) click to toggle source
# File lib/tokyo_metro/api.rb, line 94
def numbers_of_constants( ary_for_display )
  puts "Set api constants"
  puts "  - Please select constant number(s)."
  puts "  - If you want to set multiple constants, please input the number of each constant and input a space between them."
  puts ""

  ary_for_display.each_with_index do | constant , i |
    puts ( constant.to_s.ljust(24) + " : " + i.to_s.rjust(2) )
    if i == 0
      puts ""
    end
  end

  puts ""

  numbers = ::STDIN.gets.chomp
  unless /\A\d+(?: \d+)*\Z/ === numbers
    return numbers_of_constants( ary_for_display )
  end

  ary = numbers.split( / / ).map( &:to_i ).sort
  if ary.include?(0) and ary.length > 1
    puts "Do you want to set no constant? Multiple numbers are input."
    numbers_of_constants( ary_for_display )
  end

  ary
end
set_config_of_api_constants( *configs_of_api_constants ) click to toggle source
# File lib/tokyo_metro/api.rb, line 54
def set_config_of_api_constants( *configs_of_api_constants )
  if configs_of_api_constants.blank? or configs_of_api_constants.all?( &:blank? )
    ary_for_display = ::Array.new
    ary_for_display << :none
    list_of_constants.each do | constant |
      ary_for_display << constant
    end

    numbers = numbers_of_constants( ary_for_display )

    if numbers.include?(0)
      return nil
    end

    h = ::Hash.new
    numbers.each do | i |
      h[ ary_for_display[i] ] = true
    end

    return h

  elsif configs_of_api_constants.instance_of?( ::Array )
    if configs_of_api_constants.length == 1 and configs_of_api_constants.first.instance_of?( ::Hash )
      h = configs_of_api_constants.first
      if h.keys.all? { | key | list_of_constants.include?( key ) }
        return h
      end

    elsif configs_of_api_constants.all? { | item | ( item.instance_of?( ::String ) or item.instance_of?( ::Symbol ) ) and list_of_constants.include?( item ) }
      h = ::Hash.new
      configs_of_api_constants.each do | key |
        h[ key.intern ] = true
      end
      return h
    end
  end

  raise "Error: #{ configs_of_api_constants.to_s } is not valid."
end
set_constant( const_name_underscore ) click to toggle source
# File lib/tokyo_metro/api.rb, line 46
def set_constant( const_name_underscore )
  const_name_base = const_name_underscore.to_s.underscore.downcase
  const_name = const_name_base.upcase.intern
  class_name = "::TokyoMetro::Api::#{ const_name_base.camelize }"
  puts const_name.to_s.ljust(48) + class_name
  const_set( const_name , eval( class_name ).generate_from_saved_json )
end