class Spoonerize::Log
Class that handles reading/writing logs.
Attributes
directory[R]
The directory the file is located.
@return [String]
file[R]
The file name to use.
@return [String]
Public Class Methods
new(file)
click to toggle source
Constructor for Log
.
@param [String] file
@return [Spoonerize::Log]
# File lib/spoonerize/log.rb, line 27 def initialize(file) @file = File.expand_path(file) @directory = File.dirname(file) FileUtils.mkdir_p(directory) unless File.directory?(directory) FileUtils.touch(file) unless File.file?(file) end
Public Instance Methods
contents()
click to toggle source
The contents of the log file.
@return [Array]
# File lib/spoonerize/log.rb, line 38 def contents ::CSV.read(file) end
each() { |row| ... }
click to toggle source
Iterate through each line of the file.
@return [Array]
# File lib/spoonerize/log.rb, line 56 def each contents.each { |row| yield row } end
size()
click to toggle source
Number of entries in the file.
@return [Integer]
# File lib/spoonerize/log.rb, line 64 def size contents.size end
write(row)
click to toggle source
Writes a line to the log.
@param [Array] row
@return [Array]
# File lib/spoonerize/log.rb, line 48 def write(row) ::CSV.open(file, 'a') { |csv| csv << row } end