module Utilrb::Timepoints

Public Instance Methods

add_timepoint(*names) click to toggle source
# File lib/utilrb/timepoints.rb, line 12
def add_timepoint(*names)
    @timepoints ||= Array.new
    @timepoints << [Time.now, names]
end
clear_timepoints() click to toggle source
# File lib/utilrb/timepoints.rb, line 7
def clear_timepoints
    @timepoints ||= Array.new
    @timepoints.clear
end
format_timepoints() click to toggle source
# File lib/utilrb/timepoints.rb, line 17
def format_timepoints
    start_points = Hash.new
    result = []
    @timepoints.inject(@timepoints.first.first) do |last_t, (t, name)|
        if name.last == 'start'
            start_points[name[0..-2]] = t
        elsif name.last == 'done'
            total = t - start_points.delete(name[0..-2])
            name = name + ["total=%.3f" % total]
        end
        result << name + [t - last_t]
        t
    end
    result
end
merge_timepoints(other) click to toggle source
# File lib/utilrb/timepoints.rb, line 33
def merge_timepoints(other)
    data =
        if other.respond_to?(:to_ary)
            other.to_ary
        else
            other.timepoints
        end
    @timepoints = (timepoints + data).sort_by(&:first)
    self
end
timepoints() click to toggle source
# File lib/utilrb/timepoints.rb, line 3
def timepoints
    @timepoints || Array.new
end