class SimpleLog
Public Class Methods
new(name = "log", format="txt")
click to toggle source
Only supports annotation
# 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
Public Instance Methods
annotate(annotation, name=nil, options = {})
click to toggle source
# 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={})
click to toggle source
# 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={})
click to toggle source
# 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={})
click to toggle source
Interface Functions ===================================
# 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()
click to toggle source
# File lib/simplelog.rb, line 154 def get_data_as_points [[0,0]] end
get_data_as_xy()
click to toggle source
# File lib/simplelog.rb, line 158 def get_data_as_xy [[0],[0]] end
get_series_hashes()
click to toggle source
# File lib/simplelog.rb, line 162 def get_series_hashes {0 => 0} end
get_timestamp()
click to toggle source
# File lib/simplelog.rb, line 150 def get_timestamp() Time.now.strftime("%Y-%m-%d-%H%M%S") end
log(content, name = nil)
click to toggle source
# 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)
click to toggle source
# File lib/simplelog.rb, line 106 def log_name(name = nil) name = translate_name(name) log("<For #{name}>:") end
log_var(var, name=nil)
click to toggle source
# 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={})
click to toggle source
# File lib/simplelog.rb, line 47 def new_data( x=[], y=[],name=nil, options={}) end
parse_var(var, indent)
click to toggle source
# 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)
click to toggle source
# File lib/simplelog.rb, line 142 def put_at_indent(content, indent) string = "" indent.times { string += " "} string += content + "\n" end
save()
click to toggle source
# File lib/simplelog.rb, line 166 def save() @file.close end
set_hash(hash ={}, name=nil, options={})
click to toggle source
# 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 = {})
click to toggle source
# File lib/simplelog.rb, line 86 def set_options(name=nil, options = {}) log_var(option, "Options") end
set_points(points = [], name=nil, options={})
click to toggle source
# 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={})
click to toggle source
# File lib/simplelog.rb, line 39 def set_x_Data(data, name, options={}) end
set_xy(x=[], y=[], name=nil, options={})
click to toggle source
# 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={})
click to toggle source
# File lib/simplelog.rb, line 43 def set_y_data(data, name, options={}) end
translate_name(name)
click to toggle source
# File lib/simplelog.rb, line 30 def translate_name(name) if name == nil name = @current_name end return name end