Class: Noter::FileMaker

Inherits:
Object
  • Object
show all
Defined in:
lib/noter/file_maker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, filename = nil) ⇒ FileMaker

Returns a new instance of FileMaker.



7
8
9
10
# File 'lib/noter/file_maker.rb', line 7

def initialize(content = nil, filename = nil)
  @content = content
  @filename = filename
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/noter/file_maker.rb', line 5

def content
  @content
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/noter/file_maker.rb', line 5

def filename
  @filename
end

Instance Method Details

#create_empty_fileObject



32
33
34
35
36
37
# File 'lib/noter/file_maker.rb', line 32

def create_empty_file
  filename = new_filename
  content = ""
  File.write(filename, content)
  filename
end

#dirObject



12
13
14
# File 'lib/noter/file_maker.rb', line 12

def dir
  NoteFile.dir
end

#make_from_file(filename) ⇒ Object



27
28
29
30
# File 'lib/noter/file_maker.rb', line 27

def make_from_file(filename)
  content = File.read(filename)
  File.write(new_filename, content)
end

#new_filenameObject



16
17
18
# File 'lib/noter/file_maker.rb', line 16

def new_filename
  @filename ||= "#{dir}/#{Time.now.strftime('%Y_%m_%d_%H_%M_%S.txt')}"
end

#save_fileObject



20
21
22
23
24
25
# File 'lib/noter/file_maker.rb', line 20

def save_file
  unless File.exist?(dir)
    FileUtils.mkpath(dir)
  end
  File.write(new_filename, content)
end