Sha256: 52dce79b3dc0c6fb462a0f46a84b54642c24a1c3081f4ba99138c51bce1c516f

Contents?: true

Size: 609 Bytes

Versions: 4

Compression:

Stored size: 609 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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
noter-0.3.0 lib/noter/file_maker.rb
noter-0.2.0 lib/noter/file_maker.rb
noter-0.1.0 lib/noter/file_maker.rb
noter-0.0.2 lib/noter/file_maker.rb