Class: Dream::Spectre

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

Instance Method Summary collapse

Constructor Details

#initialize(library) ⇒ Spectre

Returns a new instance of Spectre.



6
7
8
9
10
11
12
# File 'lib/dream.rb', line 6

def initialize(library)
  @library = library
  @messages = library['records']['messages']
  @format = library['records']['format']
  @watches = {}
  @book = Array.new
end

Instance Method Details

#author(book) ⇒ Object



70
71
72
# File 'lib/dream.rb', line 70

def author(book)
  @book = book
end

#clean(path) ⇒ Object



90
91
92
# File 'lib/dream.rb', line 90

def clean(path)
  return FileUtils.rm_rf(path)
end

#errorObject



58
59
60
# File 'lib/dream.rb', line 58

def error
  return @messages['error']
end

#finishedObject



42
43
44
# File 'lib/dream.rb', line 42

def finished
  return @messages['finished']
end

#infoObject



50
51
52
# File 'lib/dream.rb', line 50

def info
  return @messages['info']
end

#manuscript(clear) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/dream.rb', line 62

def manuscript(clear)
  replica = @book
  if clear
    @book = Array.new
  end
  return replica
end

#record(status, directory, message) ⇒ Object



14
15
16
17
18
19
20
# 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_finishedObject



26
27
28
# File 'lib/dream.rb', line 26

def record_finished()
  watch(@messages['finished'])
end

#record_startObject



22
23
24
# File 'lib/dream.rb', line 22

def record_start()
  watch(@messages['started'])
end

#save(path) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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

#startedObject



38
39
40
# File 'lib/dream.rb', line 38

def started
  return @messages['started']
end

#successObject



46
47
48
# File 'lib/dream.rb', line 46

def success
  return @messages['success']
end

#time_records(name) ⇒ Object



34
35
36
# File 'lib/dream.rb', line 34

def time_records(name)
  return @watches[:"#{name}"]
end

#warningObject



54
55
56
# File 'lib/dream.rb', line 54

def warning
  return @messages['warning']
end

#watch(name) ⇒ Object



30
31
32
# File 'lib/dream.rb', line 30

def watch(name)
  @watches[:"#{name}"] = timestamp()
end