Class: Noter::FileMaker
- Inherits:
-
Object
- Object
- Noter::FileMaker
- Defined in:
- lib/noter/file_maker.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #create_empty_file ⇒ Object
- #dir ⇒ Object
-
#initialize(content = nil, filename = nil) ⇒ FileMaker
constructor
A new instance of FileMaker.
- #make_from_file(filename) ⇒ Object
- #new_filename ⇒ Object
- #save_file ⇒ Object
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/noter/file_maker.rb', line 5 def content @content end |
#filename ⇒ Object (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_file ⇒ Object
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 |
#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_filename ⇒ Object
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_file ⇒ Object
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 |