class TokyoMetro::Factory::Save::Api::MetaClass::Group

グループ化されたデータを保存するためのクラス(メタクラス)

Attributes

db_dir[R]
file_type[R]

Public Class Methods

file_info_class_for_saving() click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 65
def self.file_info_class_for_saving
  error_msg = [
    "Error: This class method \'#{ __method__ }\' is not defind yet in this class \'#{self.name}\'." ,
    "Please set an constant indicating sub-class of \'::TokyoMetro::Factory::Save::Api::MetaClass::Group::FileInfo\'."
  ].join( "\n" )
  raise error_msg
end
key_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_not_generated() click to toggle source

API の情報(ハッシュの配列)の各成分をディレクトリ分けするときに使用するキーの設定

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 83
def self.key_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_not_generated
  error_msg = [
    "Error: This class method \'#{ __method__ }\' is not defind yet in this class \'#{self.name}\'." ,
    "Please set a string indicating hash key name."
  ].join( "\n" )
  raise error_msg
end
list_class_for_saving_grouped_infos() click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 57
def self.list_class_for_saving_grouped_infos
  error_msg = [
    "Error: This class method \'#{ __method__ }\' is not defind yet in this class \'#{self.name}\'." ,
    "Please set an constant indicating sub-class of \'::TokyoMetro::Factory::Save::Api::MetaClass::Group::List\'."
  ].join( "\n" )
  raise error_msg
end
method_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_generated() click to toggle source

API の情報(generate_instance が true のときの、インスタンスの配列)の各成分をディレクトリ分けするときに使用するキーの設定

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 74
def self.method_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_generated
  error_msg = [
    "Error: This class method \'#{ __method__ }\' is not defind yet in this class \'#{self.name}\'." ,
    "Please set a symbol indicating method name."
  ].join( "\n" )
  raise error_msg
end
new( db_dir , file_type , generate_instance , to_inspect ) click to toggle source

Constructor

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 5
def initialize( db_dir , file_type , generate_instance , to_inspect )
  @db_dir = db_dir
  @file_type = file_type

  @generate_instance = generate_instance
  @to_inspect = to_inspect
end
process( http_client , *variables , display_inspect_info: true ) click to toggle source

API の情報を取得し、ディレクトリに分けて保存するメソッド @param http_client [HTTPClient] HTTPClient のインスタンス【必須】 @note 可変長引数 必須の引数

[TokyoMetro::Factory::Save::Api::TrainLocation::Group のみ]
  @param railway_line [String] 鉄道路線【必須】 <odpt:railway - odpt:Railway>
[すべて]
@param db_dir [String] 保存先のディレクトリの名称【必須】
@param file_type [Symbol] 保存するファイルの種類【必須】
@param generate_instance [Boolean] データ取得後に Ruby のインスタンスを作成するか否かの設定【必須】
@param to_inspect [Boolean] データ取得後にコマンドツールに内容を表示するか否かの設定【必須】

@note このメソッドは、各クラスのクラスメソッド save_datas_of_each_group から呼び出される。 @return [nil]

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 48
def self.process( http_client , *variables , display_inspect_info: true )
  info = self.new( *variables )
  info.get_and_set_data( http_client )
  ary = info.to_data_list
  ary.save_datas( info.db_dir , info.file_type )

  return nil
end
settings_for_dirname_and_filename() click to toggle source

ディレクトリ、ファイル名の設定 @return [::Symbol or nil]

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 93
def self.settings_for_dirname_and_filename
  nil
end

Public Instance Methods

get_and_set_data( http_client ) click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 16
def get_and_set_data( http_client )
  @data = self.class.toplevel_namespace.get( http_client , parse_json: true , generate_instance: @generate_instance , to_inspect: @to_inspect )
end
instance_will_be_generated?() click to toggle source

(JSON から生成した)インスタンスが与えられているか否かを判定するメソッド @return [Boolean]

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 22
def instance_will_be_generated?
  @generate_instance
end
to_data_list() click to toggle source

データの保存に必要なインスタンス(配列)を返すメソッド (1) - インスタンスメソッド @return [::TokyoMetro::Factory::Save::Api::MetaClass::Group::List <FileInfo>]

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 28
def to_data_list
  ary = self.class.list_class_for_saving_grouped_infos.new
  grouped_data.each do | key , value_ary |
    ary << self.class.file_info_class_for_saving.new( value_ary , key )
  end
  ary
end

Private Instance Methods

check_validity_before_grouping_data() click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 109
def check_validity_before_grouping_data
  if @data.nil?
    raise "Error"
  end
end
grouped_data() click to toggle source

@return [Hash]

# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 100
def grouped_data
  check_validity_before_grouping_data
  if instance_will_be_generated?
    grouped_data_when_instance_is_generated
  else
    grouped_data_when_instance_is_not_generated
  end
end
grouped_data_when_instance_is_generated() click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 115
def grouped_data_when_instance_is_generated
  h = @data.group_by { | element_of_list |
    element_of_list.send( self.class.method_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_generated )
  }

  h_new = ::Hash.new
  h.each do | key , ary |
    h_new[ key ] = ary.map( &:to_h )
  end
  h_new
end
grouped_data_when_instance_is_not_generated() click to toggle source
# File lib/tokyo_metro/factory/save/api/meta_class/group.rb, line 127
def grouped_data_when_instance_is_not_generated
  @data.group_by { | element_of_list |
    element_of_list[ self.class.key_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_not_generated ]
  }
end