class Dream::Spectre
Public Class Methods
new(library)
click to toggle source
# File lib/dream.rb, line 6 def initialize(library) @library = library @messages = library['records']['messages'] @format = library['records']['format'] @watches = {} @book = Array.new end
Public Instance Methods
clean(path)
click to toggle source
# File lib/dream.rb, line 90 def clean(path) return FileUtils.rm_rf(path) end
error()
click to toggle source
# File lib/dream.rb, line 58 def error return @messages['error'] end
finished()
click to toggle source
# File lib/dream.rb, line 42 def finished return @messages['finished'] end
info()
click to toggle source
# File lib/dream.rb, line 50 def info return @messages['info'] end
manuscript(clear)
click to toggle source
# File lib/dream.rb, line 62 def manuscript(clear) replica = @book if clear @book = Array.new end return replica end
record(status, directory, message)
click to toggle source
# File lib/dream.rb, line 14 def record(status, directory, message) timestamp = Time.now path = directory.split("/") node = branch(path[0..-2]) record = timeline(path[-1], timestamp, status, message) node.push(record) end
record_finished()
click to toggle source
# File lib/dream.rb, line 26 def record_finished() watch(@messages['finished']) end
record_start()
click to toggle source
# File lib/dream.rb, line 22 def record_start() watch(@messages['started']) end
save(path)
click to toggle source
# File lib/dream.rb, line 74 def save(path) path = path.eql?(nil) ? '.' : path iteration = 0 name = record_name(iteration) record_path = "#{path}/#{name}" while File.exist?(record_path) iteration = iteration + 1 name = record_name(iteration) record_path = "#{path}/#{name}" end File.open(record_path, "w+") do |f| f.puts(@book.to_json) end return record_path end
started()
click to toggle source
# File lib/dream.rb, line 38 def started return @messages['started'] end
success()
click to toggle source
# File lib/dream.rb, line 46 def success return @messages['success'] end
time_records(name)
click to toggle source
# File lib/dream.rb, line 34 def time_records(name) return @watches[:"#{name}"] end
warning()
click to toggle source
# File lib/dream.rb, line 54 def warning return @messages['warning'] end
watch(name)
click to toggle source
# File lib/dream.rb, line 30 def watch(name) @watches[:"#{name}"] = timestamp() end
Private Instance Methods
branch(branches)
click to toggle source
# File lib/dream.rb, line 107 def branch(branches) edge = @book branches.each do | branch | if edge[-1]["name"].eql?(branch) edge = edge[-1]["children"] else break end end return edge end
record_name(iteration)
click to toggle source
# File lib/dream.rb, line 119 def record_name(iteration) timestamp = @library['records']['timestamp'] ? "-#{Time.now.strftime "%Y%m%d%H%M%S-%L"}" : "" if iteration.eql?(0) return "#{@library['records']['name']}#{timestamp}.#{@library['records']['extension']}" else return "#{@library['records']['name']}#{timestamp}-#{iteration}.#{@library['records']['extension']}" end end
timeline(name, timestamp, status, message)
click to toggle source
# File lib/dream.rb, line 96 def timeline(name, timestamp, status, message) record = { "name" => name, "timestamp" => timestamp, "status" => status, "message" => message, "children" => [] } return record end
timestamp()
click to toggle source
# File lib/dream.rb, line 128 def timestamp() return Time.now.strftime "%Y-%m-%dT%H:%M:%S.%LZ" end