Class: TokyoMetro::Factory::Save::Api::MetaClass::Group
- Inherits:
-
Object
- Object
- TokyoMetro::Factory::Save::Api::MetaClass::Group
- Defined in:
- lib/tokyo_metro/factory/save/api/meta_class/group.rb
Overview
グループ化されたデータを保存するためのクラス(メタクラス)
Direct Known Subclasses
Fare::Group, PassengerSurvey::Group, Point::Group, RailwayLine::Group, Station::Group, StationFacility::Group, StationTimetable::Group, TrainLocation::Group, TrainOperation::Group, TrainTimetable::Group
Defined Under Namespace
Instance Attribute Summary collapse
-
#db_dir ⇒ Object
readonly
Returns the value of attribute db_dir.
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
Class Method Summary collapse
- .file_info_class_for_saving ⇒ Object
-
.key_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_not_generated ⇒ Object
API の情報(ハッシュの配列)の各成分をディレクトリ分けするときに使用するキーの設定.
- .list_class_for_saving_grouped_infos ⇒ Object
-
.method_name_for_determining_dir_when_saving_grouped_infos_and_instance_is_generated ⇒ Object
API の情報(generate_instance が true のときの、インスタンスの配列)の各成分をディレクトリ分けするときに使用するキーの設定.
-
.process(http_client, *variables, display_inspect_info: true) ⇒ nil
API の情報を取得し、ディレクトリに分けて保存するメソッド.
-
.settings_for_dirname_and_filename ⇒ ::Symbol or nil
ディレクトリ、ファイル名の設定.
Instance Method Summary collapse
- #get_and_set_data(http_client) ⇒ Object
-
#initialize(db_dir, file_type, generate_instance, to_inspect) ⇒ Group
constructor
Constructor.
-
#instance_will_be_generated? ⇒ Boolean
(JSON から生成した)インスタンスが与えられているか否かを判定するメソッド.
-
#to_data_list ⇒ ::TokyoMetro::Factory::Save::Api::MetaClass::Group::List <FileInfo>
データの保存に必要なインスタンス(配列)を返すメソッド (1) - インスタンスメソッド.
Constructor Details
#initialize(db_dir, file_type, generate_instance, to_inspect) ⇒ Group
Constructor
5 6 7 8 9 10 11 |
# 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 |
Instance Attribute Details
#db_dir ⇒ Object (readonly)
Returns the value of attribute db_dir.
13 14 15 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/group.rb', line 13 def db_dir @db_dir end |
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
14 15 16 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/group.rb', line 14 def file_type @file_type end |
Class Method Details
.file_info_class_for_saving ⇒ Object
65 66 67 68 69 70 71 |
# 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 ⇒ Object
API の情報(ハッシュの配列)の各成分をディレクトリ分けするときに使用するキーの設定
83 84 85 86 87 88 89 |
# 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 ⇒ Object
57 58 59 60 61 62 63 |
# 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 ⇒ Object
API の情報(generate_instance が true のときの、インスタンスの配列)の各成分をディレクトリ分けするときに使用するキーの設定
74 75 76 77 78 79 80 |
# 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 |
.process(http_client, *variables, display_inspect_info: true) ⇒ nil
可変長引数 必須の引数
- 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] データ取得後にコマンドツールに内容を表示するか否かの設定【必須】
このメソッドは、各クラスのクラスメソッド save_datas_of_each_group から呼び出される。
API の情報を取得し、ディレクトリに分けて保存するメソッド
48 49 50 51 52 53 54 55 |
# 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 ⇒ ::Symbol or nil
ディレクトリ、ファイル名の設定
93 94 95 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/group.rb', line 93 def self.settings_for_dirname_and_filename nil end |
Instance Method Details
#get_and_set_data(http_client) ⇒ Object
16 17 18 |
# 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? ⇒ Boolean
(JSON から生成した)インスタンスが与えられているか否かを判定するメソッド
22 23 24 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/group.rb', line 22 def instance_will_be_generated? @generate_instance end |
#to_data_list ⇒ ::TokyoMetro::Factory::Save::Api::MetaClass::Group::List <FileInfo>
データの保存に必要なインスタンス(配列)を返すメソッド (1) - インスタンスメソッド
28 29 30 31 32 33 34 |
# 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 |