Class: Kuromd::Journal::Inbox

Inherits:
Object
  • Object
show all
Defined in:
lib/kuromd/journal/inbox.rb

Overview

represents an Inbox folder

Instance Method Summary collapse

Constructor Details

#initialize(inbox_path:) ⇒ Inbox

Returns a new instance of Inbox.



9
10
11
12
13
14
# File 'lib/kuromd/journal/inbox.rb', line 9

def initialize(inbox_path:)
  raise 'Inbox path required' if inbox_path.nil? == true

  @inbox_fullpath = File.expand_path(inbox_path)
  @created = File.exist?(@inbox_fullpath)
end

Instance Method Details

#createObject

creates the inbox folder (if it isn’t created)



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

def create
  FileUtils.mkdir_p @inbox_fullpath if @created == false
  @created = true
end

#lsObject

list files in the inbox folder



23
24
25
# File 'lib/kuromd/journal/inbox.rb', line 23

def ls
  Dir[@inbox_fullpath]
end

#save(filename:, journal_date: Date.today) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/kuromd/journal/inbox.rb', line 27

def save(filename:, journal_date: Date.today)
  _filename = File.expand_path(filename)
  _basename = File.basename _filename
  inbox_filename = "#{journal_date} - #{_basename}"
  dest_file = File.join(@inbox_fullpath, inbox_filename)
  FileUtils.mv _filename, dest_file
end