Class: RubyMethodTracer::Formatters::BaseFormatter
- Inherits:
-
Object
- Object
- RubyMethodTracer::Formatters::BaseFormatter
- Defined in:
- lib/ruby_method_tracer/formatters/base_formatter.rb
Overview
Base class for formatting trace output
Direct Known Subclasses
Instance Method Summary collapse
-
#colorize(text, color) ⇒ String
Apply color to text using ANSI escape codes.
-
#format(_data) ⇒ Object
Abstract method to be implemented by subclasses.
-
#format_time(seconds) ⇒ String
Format timing value into human-readable string.
Instance Method Details
#colorize(text, color) ⇒ String
Apply color to text using ANSI escape codes
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_method_tracer/formatters/base_formatter.rb', line 26 def colorize(text, color) colors = { red: "31", green: "32", yellow: "33", blue: "34", magenta: "35", cyan: "36", white: "37", reset: "0" } "\e[#{colors[color]}m#{text}\e[#{colors[:reset]}m" end |
#format(_data) ⇒ Object
Abstract method to be implemented by subclasses
44 45 46 |
# File 'lib/ruby_method_tracer/formatters/base_formatter.rb', line 44 def format(_data) raise NotImplementedError, "#{self.class} must implement #format" end |
#format_time(seconds) ⇒ String
Format timing value into human-readable string
11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby_method_tracer/formatters/base_formatter.rb', line 11 def format_time(seconds) if seconds >= 1.0 "#{seconds.round(3)}s" elsif seconds >= 0.001 "#{(seconds * 1000).round(1)}ms" else "#{(seconds * 1_000_000).round(0)}µs" end end |