Class: SimpleLog
Instance Method Summary
collapse
-
#annotate(annotation, name = nil, options = {}) ⇒ Object
-
#appendHash(hash = {}, name = nil, options = {}) ⇒ Object
-
#appendPoints(points = [], name = nil, options = {}) ⇒ Object
-
#appendXY(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================.
-
#getDataAsPoints ⇒ Object
-
#getDataAsXY ⇒ Object
-
#getSeriesHashes ⇒ Object
-
#getTimestamp ⇒ Object
-
#initialize(name = "log", format = "txt") ⇒ SimpleLog
constructor
Only supports annotation.
-
#log(content, name = nil) ⇒ Object
-
#log_name(name = nil) ⇒ Object
-
#log_var(var, name = nil) ⇒ Object
-
#newData(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#parse_var(var, indent) ⇒ Object
-
#put_at_indent(content, indent) ⇒ Object
-
#save ⇒ Object
-
#setHash(hash = {}, name = nil, options = {}) ⇒ Object
-
#setOptions(name = nil, options = {}) ⇒ Object
-
#setPoints(points = [], name = nil, options = {}) ⇒ Object
-
#setXData(data, name, options = {}) ⇒ Object
-
#setXY(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#setYData(data, name, options = {}) ⇒ Object
-
#translate_name(name) ⇒ Object
#advance_series, #append_callback, #append_series_name, #new_data_callback, #options_callback, #set_x_callback, #set_y_callback
Constructor Details
#initialize(name = "log", format = "txt") ⇒ SimpleLog
20
21
22
23
24
25
26
27
28
|
# File 'lib/simplelog.rb', line 20
def initialize(name = "log", format="txt")
filename = name + self.getTimestamp() + "." + format
@file = File.new(filename, "w")
@series_names = {}
@data_id = 0
@annotations = {}
@current_name = ""
@series_id = 0
end
|
Instance Method Details
#annotate(annotation, name = nil, options = {}) ⇒ Object
90
91
92
93
94
|
# File 'lib/simplelog.rb', line 90
def annotate(annotation, name=nil, options = {})
name = translate_name(name)
log(annotation, name)
self.options_callback(options)
end
|
#appendHash(hash = {}, name = nil, options = {}) ⇒ Object
74
75
76
77
|
# File 'lib/simplelog.rb', line 74
def appendHash(hash = {}, name=nil, options={})
log_name(name)
log_var(hash, "Appending (hash)")
end
|
#appendPoints(points = [], name = nil, options = {}) ⇒ Object
64
65
66
67
|
# File 'lib/simplelog.rb', line 64
def appendPoints(points =[], name=nil, options={})
log_name(name)
log_var(points, "Appending (points)")
end
|
#appendXY(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================
52
53
54
55
56
|
# File 'lib/simplelog.rb', line 52
def appendXY( x=[], y=[],name=nil, options={})
log_name(name)
log_var(x, "Appending X Data")
log_var(y, "Appending Y Data")
end
|
#getDataAsPoints ⇒ Object
154
155
156
|
# File 'lib/simplelog.rb', line 154
def getDataAsPoints
[[0,0]]
end
|
#getDataAsXY ⇒ Object
158
159
160
|
# File 'lib/simplelog.rb', line 158
def getDataAsXY
[[0],[0]]
end
|
#getSeriesHashes ⇒ Object
162
163
164
|
# File 'lib/simplelog.rb', line 162
def getSeriesHashes
{0 => 0}
end
|
#getTimestamp ⇒ Object
150
151
152
|
# File 'lib/simplelog.rb', line 150
def getTimestamp()
Time.now.strftime("%Y-%m-%d-%H%M%S")
end
|
#log(content, name = nil) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/simplelog.rb', line 96
def log(content, name = nil)
if name != nil
logtext = self.getTimestamp() + " #{name}: #{content}"
else
logtext = self.getTimestamp() + " #{content}"
end
puts logtext
@file.syswrite("#{logtext}\n")
end
|
#log_name(name = nil) ⇒ Object
106
107
108
109
|
# File 'lib/simplelog.rb', line 106
def log_name(name = nil)
name = translate_name(name)
log("<For #{name}>:")
end
|
#log_var(var, name = nil) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/simplelog.rb', line 111
def log_var(var, name=nil)
log("value:", name)
str = parse_var(var,1)
puts str
@file.syswrite("#{str}\n")
end
|
#newData(x = [], y = [], name = nil, options = {}) ⇒ Object
47
48
49
|
# File 'lib/simplelog.rb', line 47
def newData( x=[], y=[],name=nil, options={})
end
|
#parse_var(var, indent) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/simplelog.rb', line 118
def parse_var(var, indent)
string = ""
case var
when Hash
string += self.put_at_indent("Hash:", indent)
var.each_pair do |(key, value)|
string += self.put_at_indent(key.to_s, indent+1)
string += self.parse_var(value, indent+1)
end
when Array
string += self.put_at_indent("Array:", indent)
var.each do |value|
string += self.parse_var(value, indent+1)
end
when Numeric
string += self.put_at_indent(var.to_s, indent)
when String
string += self.put_at_indent(var, indent)
else
string += self.put_at_indent(var.to_s, indent)
end
string
end
|
#put_at_indent(content, indent) ⇒ Object
142
143
144
145
146
|
# File 'lib/simplelog.rb', line 142
def put_at_indent(content, indent)
string = ""
indent.times { string += " "}
string += content + "\n"
end
|
#save ⇒ Object
166
167
168
|
# File 'lib/simplelog.rb', line 166
def save()
@file.close
end
|
#setHash(hash = {}, name = nil, options = {}) ⇒ Object
79
80
81
82
|
# File 'lib/simplelog.rb', line 79
def setHash(hash ={}, name=nil, options={})
log_name(name)
log_var(hash, "Setting (hash)")
end
|
#setOptions(name = nil, options = {}) ⇒ Object
86
87
88
|
# File 'lib/simplelog.rb', line 86
def setOptions(name=nil, options = {})
log_var(option, "Options")
end
|
#setPoints(points = [], name = nil, options = {}) ⇒ Object
69
70
71
72
|
# File 'lib/simplelog.rb', line 69
def setPoints(points = [], name=nil, options={})
log_name(name)
log_var(points, "Setting (points)")
end
|
#setXData(data, name, options = {}) ⇒ Object
39
40
41
|
# File 'lib/simplelog.rb', line 39
def setXData(data, name, options={})
end
|
#setXY(x = [], y = [], name = nil, options = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/simplelog.rb', line 58
def setXY(x=[], y=[], name=nil, options={})
log_name(name)
log_var(x, "Setting X Data")
log_var(y, "Setting Y Data")
end
|
#setYData(data, name, options = {}) ⇒ Object
43
44
45
|
# File 'lib/simplelog.rb', line 43
def setYData(data, name, options={})
end
|
#translate_name(name) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/simplelog.rb', line 30
def translate_name(name)
if name == nil
name = @current_name
end
return name
end
|