Class: TokyoMetro::Factory::Save::Api::MetaClass::EachFile::Fundamental
- Inherits:
-
Object
- Object
- TokyoMetro::Factory::Save::Api::MetaClass::EachFile::Fundamental
- Defined in:
- lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb
Overview
API から取得したデータなどを保存するための Factory Pattern クラス
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#db_dir ⇒ Object
readonly
Returns the value of attribute db_dir.
-
#dirname_base ⇒ Object
readonly
Returns the value of attribute dirname_base.
-
#file_type ⇒ Object
readonly
Returns the value of attribute file_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Class Method Summary collapse
Instance Method Summary collapse
- #filename_fullpass ⇒ Object
-
#initialize(data, filename = Time.now.strftime( "%Y%m%d" ), db_dir: nil, dirname_sub: nil, file_type: :yaml) ⇒ Fundamental
constructor
Constructor.
- #save_to_file ⇒ Object
Constructor Details
#initialize(data, filename = Time.now.strftime( "%Y%m%d" ), db_dir: nil, dirname_sub: nil, file_type: :yaml) ⇒ Fundamental
Constructor
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 6 def initialize( data , filename = Time.now.strftime( "%Y%m%d" ) , db_dir: nil , dirname_sub: nil , file_type: :yaml ) check_validity_of_data( data ) @data = data @filename = filename @db_dir = set_db_dirname( db_dir ) @dirname_base = set_dirname_base( dirname_sub ) @file_type = file_type end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 19 def data @data end |
#db_dir ⇒ Object (readonly)
Returns the value of attribute db_dir.
19 20 21 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 19 def db_dir @db_dir end |
#dirname_base ⇒ Object (readonly)
Returns the value of attribute dirname_base.
19 20 21 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 19 def dirname_base @dirname_base end |
#file_type ⇒ Object (readonly)
Returns the value of attribute file_type.
19 20 21 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 19 def file_type @file_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
19 20 21 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 19 def filename @filename end |
Class Method Details
.process(data, filename, db_dir, dirname_sub, file_type) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 46 def self.process( data , filename , db_dir , dirname_sub , file_type ) # puts "\n" * 2 # puts "Begin Process" # puts "db_dir: #{ db_dir }" # puts "file_type: #{ file_type }" # puts "" info = self.new( data , filename , db_dir: db_dir , dirname_sub: dirname_sub , file_type: file_type ) # puts "filename: #{ info.filename }" # puts "db_dir: #{ info.db_dir }" # puts "dirname_base: #{ info.dirname_base }" # puts "Fullpass: #{ info.filename_fullpass }" info.save_to_file end |
Instance Method Details
#filename_fullpass ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 21 def filename_fullpass if /[\.\/]/ === @filename splited_ary = @filename.split( /[\.\/]/ ) filename = splited_ary.pop "#{ @dirname_base }\/#{ splited_ary.join( "\/" ) }\/#{ filename }" else "#{ @dirname_base }\/#{ @filename }" end end |
#save_to_file ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tokyo_metro/factory/save/api/meta_class/each_file/fundamental.rb', line 31 def save_to_file chdir_to_dir_of_file filename = File.basename( self.filename_fullpass ) case @file_type when :txt save_as_txt( filename ) when :json save_as_json( filename ) when :yaml , :yml save_as_yaml( filename ) else raise "Error" end end |