Class: FileHandler

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

Overview

Handles the Reading and writing of files

Instance Method Summary collapse

Instance Method Details

#content(plmat) ⇒ Object

Retrieves the content as text of a file

Arguments:

* plmat (File) - a .plmat file in .plmat markdown

Return:

* (String) - contents of .plmat file


16
17
18
19
# File 'lib/placemat.rb', line 16

def content(plmat)
  file = File.open(plmat, "rb")
  file.read
end

#output(contents, filename = "output.html") ⇒ Object

Creates or overwrites text to a new file

Arguments:

* contents (String) - string of text to write to file
* filename (String) - name for new file, defaults to output.html if not specified


27
28
29
30
31
# File 'lib/placemat.rb', line 27

def output(contents, filename = "output.html")
  out_file = File.new(filename, "w")
  out_file.puts(contents)
  out_file.close
end