class TokyoMetro::Factory::Seed::Api::StationTimetable::Info::TrainTime::Info::UpdateTrainTimetable

Constants

TRAIN_TIMETABLE_OPTIONAL_INFOS

Public Class Methods

new( train , station_timetable_in_db , train_timetable_in_db ) click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 12
def initialize( train , station_timetable_in_db , train_timetable_in_db )
  @train = train
  @station_timetable_in_db = station_timetable_in_db
  @train_timetable_in_db = train_timetable_in_db

  @hash_for_update = ::Hash.new
end
process( train , station_timetable , train_timetable ) click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 25
def self.process( train , station_timetable , train_timetable )
  self.new( train , station_timetable , train_timetable ).process
end

Public Instance Methods

process() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 20
def process
  set_optional_infos
  update_train_timetable
end

Private Instance Methods

car_composition() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 55
def car_composition
  @train.car_composition
end
railway_line_ids() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 71
def railway_line_ids
  @station_timetable_in_db.railway_lines.pluck( :id )
end
set_optional_infos() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 31
def set_optional_infos
  self.class.train_timetable_optional_infos.each do | method_name |
    optional_info_id = self.send( method_name )
    if optional_info_id.present?
      optional_info_id_in_train_timetable = @train_timetable_in_db.send( method_name )

      # @hash_for_update への追加/エラー ここから
      if optional_info_id_in_train_timetable.nil?
        @hash_for_update[ method_name ] = optional_info_id
      else
        unless optional_info_id_in_train_timetable == optional_info_id
          error_msg = [
            "Error: #{ method_name } in the train timetable \'#{ @train_timetable_in_db.same_as }\' is not valid." ,
            "id in the train timetable: #{ optional_info_id_in_train_timetable }" ,
            "id in the station timetable: #{ optional_info_id }"
          ].join( "\n" )
          raise error_msg
        end
      end
      # @hash_for_update への追加/エラー ここまで
    end
  end
end
train_timetable_train_type_in_other_operator_id() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 67
def train_timetable_train_type_in_other_operator_id
  @train.train_type_in_other_operator_id
end
update_train_timetable() click to toggle source
# File lib/tokyo_metro/factory/seed/api/station_timetable/info/train_time/info/update_train_timetable.rb, line 75
def update_train_timetable
  if @hash_for_update.present?
    @train_timetable_in_db.update( @hash_for_update )
  end
end