Class: SimpleLog
Instance Method Summary
collapse
-
#annotate(annotation, name = nil, options = {}) ⇒ Object
-
#append_hash(hash = {}, name = nil, options = {}) ⇒ Object
-
#append_points(points = [], name = nil, options = {}) ⇒ Object
-
#append_xy(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================.
-
#get_data_as_points ⇒ Object
-
#get_data_as_xy ⇒ Object
-
#get_series_hashes ⇒ Object
-
#get_timestamp ⇒ 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
-
#new_data(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#parse_var(var, indent) ⇒ Object
-
#put_at_indent(content, indent) ⇒ Object
-
#save ⇒ Object
-
#set_hash(hash = {}, name = nil, options = {}) ⇒ Object
-
#set_options(name = nil, options = {}) ⇒ Object
-
#set_points(points = [], name = nil, options = {}) ⇒ Object
-
#set_x_Data(data, name, options = {}) ⇒ Object
-
#set_xy(x = [], y = [], name = nil, options = {}) ⇒ Object
-
#set_y_data(data, name, options = {}) ⇒ Object
-
#translate_name(name) ⇒ Object
#advance_series, #append_callback, #append_series_name, #new_data_callback, #new_data_check, #options_callback, #set_x_callback, #set_x_data, #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.get_timestamp() + "." + 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
|
#append_hash(hash = {}, name = nil, options = {}) ⇒ Object
74
75
76
77
|
# File 'lib/simplelog.rb', line 74
def append_hash(hash = {}, name=nil, options={})
log_name(name)
log_var(hash, "Appending (hash)")
end
|
#append_points(points = [], name = nil, options = {}) ⇒ Object
64
65
66
67
|
# File 'lib/simplelog.rb', line 64
def append_points(points =[], name=nil, options={})
log_name(name)
log_var(points, "Appending (points)")
end
|
#append_xy(x = [], y = [], name = nil, options = {}) ⇒ Object
Interface Functions ===================================
52
53
54
55
56
|
# File 'lib/simplelog.rb', line 52
def append_xy( x=[], y=[],name=nil, options={})
log_name(name)
log_var(x, "Appending X Data")
log_var(y, "Appending Y Data")
end
|
#get_data_as_points ⇒ Object
154
155
156
|
# File 'lib/simplelog.rb', line 154
def get_data_as_points
[[0,0]]
end
|
#get_data_as_xy ⇒ Object
158
159
160
|
# File 'lib/simplelog.rb', line 158
def get_data_as_xy
[[0],[0]]
end
|
#get_series_hashes ⇒ Object
162
163
164
|
# File 'lib/simplelog.rb', line 162
def get_series_hashes
{0 => 0}
end
|
#get_timestamp ⇒ Object
150
151
152
|
# File 'lib/simplelog.rb', line 150
def get_timestamp()
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.get_timestamp() + " #{name}: #{content}"
else
logtext = self.get_timestamp() + " #{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
|
#new_data(x = [], y = [], name = nil, options = {}) ⇒ Object
47
48
49
|
# File 'lib/simplelog.rb', line 47
def new_data( 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
|
#set_hash(hash = {}, name = nil, options = {}) ⇒ Object
79
80
81
82
|
# File 'lib/simplelog.rb', line 79
def set_hash(hash ={}, name=nil, options={})
log_name(name)
log_var(hash, "Setting (hash)")
end
|
#set_options(name = nil, options = {}) ⇒ Object
86
87
88
|
# File 'lib/simplelog.rb', line 86
def set_options(name=nil, options = {})
log_var(option, "Options")
end
|
#set_points(points = [], name = nil, options = {}) ⇒ Object
69
70
71
72
|
# File 'lib/simplelog.rb', line 69
def set_points(points = [], name=nil, options={})
log_name(name)
log_var(points, "Setting (points)")
end
|
#set_x_Data(data, name, options = {}) ⇒ Object
39
40
41
|
# File 'lib/simplelog.rb', line 39
def set_x_Data(data, name, options={})
end
|
#set_xy(x = [], y = [], name = nil, options = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/simplelog.rb', line 58
def set_xy(x=[], y=[], name=nil, options={})
log_name(name)
log_var(x, "Setting X Data")
log_var(y, "Setting Y Data")
end
|
#set_y_data(data, name, options = {}) ⇒ Object
43
44
45
|
# File 'lib/simplelog.rb', line 43
def set_y_data(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
|