Module: Kuromd::Journal::Fileable

Included in:
File, Note
Defined in:
lib/kuromd/journal/fileable.rb

Overview

defines the functions for managing files and folders for journals

Instance Method Summary collapse

Instance Method Details

#create_journal_folder(base_path:, date:) ⇒ Object



11
12
13
14
15
16
# File 'lib/kuromd/journal/fileable.rb', line 11

def create_journal_folder(base_path:, date:)
  date = Date.parse(date.to_s)
  full_date_path = build_date_path(base_path:, date:)
  Kuromd.logger.info "Creating folder #{full_date_path}" if FileUtils.mkdir_p full_date_path
  full_date_path
end

#find_date_from_filename(filepath) ⇒ Object



18
19
20
# File 'lib/kuromd/journal/fileable.rb', line 18

def find_date_from_filename(filepath)
  DatesFromString.new.find_date(filepath)[0]
end

#move(params = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/kuromd/journal/fileable.rb', line 22

def move(params = {})
  dest_folder = params[:dest_folder]
  source_file = ::File.expand_path(params[:source_path])

  dest_filename = ::File.basename(source_file)
  dest_filename = params[:rename_to] unless params[:rename_to].nil?

  destination = ::File.join(dest_folder, dest_filename)
  Kuromd.logger.info "Move: #{source_file} to #{destination}" if FileUtils.mv source_file, destination
end