Class: TokyoMetro::Factory::Seed::Api::StationTrainTime

Inherits:
Object
  • Object
show all
Includes:
ClassNameLibrary::Api::StationTrainTime
Defined in:
lib/tokyo_metro/factory/seed/api/station_train_time.rb

Overview

列車時刻の情報をDBに流し込むためのクラス

Defined Under Namespace

Classes: Checker, TrainInStationTimetable

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ StationTrainTime

Returns a new instance of StationTrainTime.



6
7
8
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 6

def initialize( info )
  @info = info
end

Class Method Details

.check_chiyoda_line_info_in_dbObject



34
35
36
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 34

def self.check_chiyoda_line_info_in_db
  ::TokyoMetro::Factory::Seed::Api::StationTrainTime::Checker.display_railway_line_info_in_db( :chiyoda )
end

.check_number(*symbol_of_railway_lines) ⇒ Object



22
23
24
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 22

def self.check_number( *symbol_of_railway_lines )
  ::TokyoMetro::Factory::Seed::Api::StationTrainTime::Checker.check_number( *symbol_of_railway_lines )
end

.compare_chiyoda_line_info_in_db_and_apiObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 38

def self.compare_chiyoda_line_info_in_db_and_api
  ary = ::Array.new

  ::TokyoMetro::Api.train_timetables.chiyoda.each do | train_timetable |
    train_timetable_instance_in_db = ::TrainTimetable.find_by_same_as( train_timetable.same_as )

    if train_timetable_instance_in_db.nil?
      raise "Error: The train timetable of \"#{ train_timetable.same_as }\" does not exist in the db."
    end

    number_of_station_train_times_in_db = train_timetable_instance_in_db.station_train_times.length
    number_of_station_train_times_in_api = train_timetable.number_of_station_times

    unless number_of_station_train_times_in_db == number_of_station_train_times_in_api
      str_ary = [
        "\"#{train_timetable.same_as}\"" ,
        "(#{train_timetable.train_type})" ,
        "---" ,
        "in db: #{ number_of_station_train_times_in_db }" ,
        "/" ,
        "api : #{ number_of_station_train_times_in_api }" ,
        diff_to_s( number_of_station_train_times_in_db , number_of_station_train_times_in_api )
      ]
      ary << str_ary.join( " " )
    end

  end
  puts ary
  return nil
end

.destroy!(*symbol_of_railway_lines) ⇒ Object



26
27
28
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 26

def self.destroy!( *symbol_of_railway_lines )
  ::TokyoMetro::Factory::Seed::Api::StationTrainTime::Checker.destroy!( *symbol_of_railway_lines )
end

.display_railway_line_info_in_db(*symbol_of_railway_lines) ⇒ Object



30
31
32
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 30

def self.display_railway_line_info_in_db( *symbol_of_railway_lines )
  ::TokyoMetro::Factory::Seed::Api::StationTrainTime::Checker.display_railway_line_info_in_db( *symbol_of_railway_lines )
end

.process(info) ⇒ Object



18
19
20
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 18

def self.process( info )
  self.new( info ).seed
end

Instance Method Details

#seedObject



10
11
12
13
14
15
16
# File 'lib/tokyo_metro/factory/seed/api/station_train_time.rb', line 10

def seed
  seed_main
  seed_optional_infos
  check_validity_after_finish_seeding

  return nil
end