class Timmy::TargetedTimerManager
Public Class Methods
start_for_line(line)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 4 def start_for_line(line) TargetedTimerDefinition.all.each do |definition| if match = match_line(line, definition.start_regex) label = get_capture(match, :label) group = get_capture(match, :group) stop_by_id_and_group(definition.id, group) started.push(TargetedTimer.new(definition, label: label, group: group)) end end end
started()
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 46 def started @started ||= [] end
stop(timer)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 26 def stop(timer) timer.stop Logger.put_timer(timer) started.delete(timer) stopped.push(timer) end
stop_all()
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 42 def stop_all started.each { |timer| stop(timer) } end
stop_by_id_and_group(id, group)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 34 def stop_by_id_and_group(id, group) matches = started .select { |timer| timer.definition.id } .select { |timer| timer.group == group } matches.each { |timer| stop(timer) } end
stop_for_line(line)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 16 def stop_for_line(line) started.each do |timer| if (stop_regex = timer.definition.stop_regex) && (match = match_line(line, stop_regex)) && get_capture(match, :group) == timer.group stop(timer) end end end
stopped()
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 50 def stopped @stopped ||= [] end
Private Class Methods
get_capture(match, name)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 60 def get_capture(match, name) match[name] rescue IndexError nil end
match_line(line, regex)
click to toggle source
# File lib/timmy/targeted_timer_manager.rb, line 56 def match_line(line, regex) line.gsub(/(\x1b\[[0-9;]*m)/, '').match(regex) end