Sha256: ae5a8902a94584000041b69ee3da47c40398e59334cb2c9ebaf8cfcfcab5050d

Contents?: true

Size: 744 Bytes

Versions: 1

Compression:

Stored size: 744 Bytes

Contents

require "fileutils"

module Noter
  class FileMaker
    attr_reader :content, :filename

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

    def dir
      NoteFile.dir
    end

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
noter-0.4.0 lib/noter/file_maker.rb