Class: TokyoMetro::Api::StationTimetable

Inherits:
MetaClass::NotRealTime show all
Includes:
ClassNameLibrary::Api::StationTimetable
Defined in:
lib/tokyo_metro/api/station_timetable.rb

Overview

Note:

各駅の平日、土曜、休日の列車着時刻、発車時刻と種別の情報を格納する。

駅時刻表 odpt:StationTimetable を扱うクラス

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, station: nil, railway_line: nil, operator: nil, railway_direction: nil, parse_json: false, generate_instance: false, to_inspect: false) ⇒ ::Array

駅時刻表 odpt:StationTimetable を取得するメソッド



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

def self.get( http_client ,
  id_urn: nil , same_as: nil , station: nil , railway_line: nil , operator: nil , railway_direction: nil ,
  parse_json: false , generate_instance: false , to_inspect: false )

  factory_for_getting.process( http_client , id_urn , same_as , station , railway_line , operator , railway_direction ,
    parse_json , generate_instance , to_inspect )
end

.get_test(time_table_of_all_stations, station_name, regexp) ⇒ nil

データ取得のテスト



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tokyo_metro/api/station_timetable.rb', line 57

def self.get_test( time_table_of_all_stations , station_name , regexp )
  puts "● #{station_name} Station"
  puts ""

  time_table_of_all_stations = generate_from_saved_json

  unless time_table_of_all_stations.empty?
    ary = time_table_of_all_stations.select{ | timetable |
      ( timetable.instance_of?( Hash ) and regexp === timetable[ "odpt:station" ] ) or ( timetable.instance_of?( self.info_class ) and regexp === timetable.station )
    }
    puts "Length: #{ary.length}"

    if ary.length > 0
      timetable_first = ary.first
      puts timetable_first.to_s

      h = timetable_first.today_s_timetable( to_hash: true )
      puts h.to_s
      # tojo = timetable_first.bound_for( stations: [ "odpt.Station:Tobu.Tojo.Kawagoeshi", "odpt.Station:Tobu.Tojo.ShinrinKoen" ] )
      # puts tojo.to_strf

      # shiki = timetable_first.bound_for( stations: "odpt.Station:Tobu.Tojo.Shiki" )
      # puts shiki.to_strf

      # after_now = timetable_first.after_now
      # puts after_now.to_strf

      # puts timetable_first.timetable_hash( first: true , last: true ).to_strf
    end
  end

end

.inspect_notes(timetables = self.generate_from_saved_json) ⇒ nil

補足情報についてのテスト



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/tokyo_metro/api/station_timetable.rb', line 92

def self.inspect_notes( timetables = self.generate_from_saved_json )
  ary = ::Array.new
  # puts timetables.class.name
  timetables.each do | timetable_for_a_direction |
    # puts timetable_for_a_direction.class.name
    timetable_for_a_direction.timetable_hash.values.each do | timetable_for_a_day |
      # puts timetable_for_a_day.class.name
      timetable_for_a_day.each do | train |
        # puts train.class.name
        note = train.note
        if note.present?
          ary << note
          # ary << note.to_s
          # ary << inspect_notes_str( note , timetable_for_a_direction.same_as )
        end
      end
    end
  end
  puts ary.flatten.uniq
end

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

駅時刻表 odpt:StationTimetable を取得し保存するメソッド



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

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

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

  save_data( data , filename , file_type: file_type )
end