Module: Utilrb::Timepoints
- Defined in:
- lib/utilrb/timepoints.rb
Instance Method Summary collapse
- #add_timepoint(*names) ⇒ Object
- #clear_timepoints ⇒ Object
- #format_timepoints ⇒ Object
- #merge_timepoints(other) ⇒ Object
- #timepoints ⇒ Object
Instance Method Details
#add_timepoint(*names) ⇒ Object
12 13 14 15 |
# File 'lib/utilrb/timepoints.rb', line 12 def add_timepoint(*names) @timepoints ||= Array.new @timepoints << [Time.now, names] end |
#clear_timepoints ⇒ Object
7 8 9 10 |
# File 'lib/utilrb/timepoints.rb', line 7 def clear_timepoints @timepoints ||= Array.new @timepoints.clear end |
#format_timepoints ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# 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 |