Class: JinyuDebugTools::RecordFormatter
- Inherits:
-
Object
- Object
- JinyuDebugTools::RecordFormatter
- Defined in:
- lib/utils/record_formatter.rb
Constant Summary collapse
- ELEMENT_MAPPING =
{ :file_name => 1, :line_number => 2, :from_method => 3, :to_method => 4, :arguments => 5 }
- REG =
“abc.rb:123:in ‘cde!’ calls fgh?, [String]”
/^(.*?)\.rb\:(\d+)\:in \`([a-zA-Z_0-9 \?\!]*?)\' calls ([a-zA-Z0-9_\?\!]+)\, \[(.*?)\]/
Class Method Summary collapse
Class Method Details
.format_raw_log(raw_log, required_element_names) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/utils/record_formatter.rb', line 14 def self.format_raw_log(raw_log, required_element_names) raw_log_lines = raw_log.each_line.map(&:chomp) p raw_log_lines.first raw_log_elements = raw_log_lines.map do |line| _, file_name, line_number, from_method, to_method, arguments_str = *REG.match(line) # [String, Array] arguments = arguments_str.split(', ') # in block in cde! from_method = from_method.split(' ').last # the same as match result, ignore the matched sentence [nil, file_name, line_number, from_method, to_method, arguments] end result = raw_log_elements.map do |raw_log_element| required_element_names.map do |required_element_name| raw_log_element[ELEMENT_MAPPING[required_element_name]] end end return result end |
.format_raw_log_file(file_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/utils/record_formatter.rb', line 39 def self.format_raw_log_file(file_name) output_file_name = "#{file_name}.record" log_raw = File.open(file_name).read result = RecordFormatter.format_raw_log(log_raw, [:from_method, :to_method]) File.open(output_file_name, 'w+') do |file| result.each do |line| file.puts(line.join(' ')) end end end |