Class: Kuromd::Journal::File
- Includes:
- Configurable, Fileable
- Defined in:
- lib/kuromd/journal/file.rb
Overview
Represents a file for a Journal process method will organize the note into it’s base folder
Constant Summary collapse
- NOTE_TYPE =
'Journal file'
Instance Attribute Summary collapse
-
#base_folder ⇒ Object
Returns the value of attribute base_folder.
-
#file_date ⇒ Object
Returns the value of attribute file_date.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Attributes inherited from BaseFile
Instance Method Summary collapse
- #cleanup_filename ⇒ Object
-
#initialize(params = {}) ⇒ File
constructor
A new instance of File.
- #process ⇒ Object
- #valid? ⇒ Boolean
Methods included from Fileable
#create_journal_folder, #find_date_from_filename, #move
Methods included from Configurable
#configure, #get_config, #set_config
Methods inherited from BaseFile
assign_file_objs, cleanup_types
Constructor Details
#initialize(params = {}) ⇒ File
Returns a new instance of File.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kuromd/journal/file.rb', line 20 def initialize(params = {}) super @config = Kuromd::Configurable.get_config @base_folder = @config.params['journal']['base_folder'] @file_path = params[:full_path] @file_date = find_date_from_filename(@file_path) Kuromd.logger.info "Initialized Journal File #{@file_path}, #{@file_date}" end |
Instance Attribute Details
#base_folder ⇒ Object
Returns the value of attribute base_folder.
18 19 20 |
# File 'lib/kuromd/journal/file.rb', line 18 def base_folder @base_folder end |
#file_date ⇒ Object
Returns the value of attribute file_date.
18 19 20 |
# File 'lib/kuromd/journal/file.rb', line 18 def file_date @file_date end |
#file_path ⇒ Object
Returns the value of attribute file_path.
18 19 20 |
# File 'lib/kuromd/journal/file.rb', line 18 def file_path @file_path end |
Instance Method Details
#cleanup_filename ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kuromd/journal/file.rb', line 31 def cleanup_filename filename = ::File.basename(@file_path) date_position = filename.index(@file_date) if date_position.zero? filename.delete_prefix!("#{@file_date} - ") else extname = ::File.extname(filename) filename.delete_suffix!(" - #{@file_date}#{extname}") filename += extname end filename end |
#process ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/kuromd/journal/file.rb', line 55 def process return unless valid? journal_folder = create_journal_folder(base_path: @base_folder, date: @file_date) move({ dest_folder: journal_folder, source_path: @file_path, rename_to: cleanup_filename }) end |