class Spoonerize::Log
Class that handles reading/writing logs. Log file is stored as a simple CSV.
Attributes
The directory the file is located.
@return [String]
The file name to use.
@return [String]
Public Class Methods
Source
# File lib/spoonerize/log.rb, line 28 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
Source
# File lib/spoonerize/log.rb, line 39 def contents ::CSV.read(file) end
The contents of the log file.
@return [Array]
Source
# File lib/spoonerize/log.rb, line 57 def each contents.each { |row| yield row } end
Iterate through each line of the file.
@return [Enumerable]
Source
# File lib/spoonerize/log.rb, line 65 def size contents.size end
Number of entries in the file.
@return [Integer]
Source
# File lib/spoonerize/log.rb, line 49 def write(row) ::CSV.open(file, "a") { |csv| csv << row } end
Writes a line to the log.
@param [Array] row
@return [Array]