Class: LogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode_warnings/log_parser.rb

Overview

Parser class for the xcodebuild log.

Defined Under Namespace

Classes: Warning

Constant Summary collapse

KEYWORD_WARNING =

The keyword for detecing warnings.

" warning: ".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#show_build_timing_summaryvoid

This method returns an undefined value.

Whether show build timing summary or not.



21
22
23
# File 'lib/xcode_warnings/log_parser.rb', line 21

def show_build_timing_summary
  @show_build_timing_summary
end

#show_build_warningsvoid

This method returns an undefined value.

Whether show build warnings or not.



13
14
15
# File 'lib/xcode_warnings/log_parser.rb', line 13

def show_build_warnings
  @show_build_warnings
end

#show_linker_warningsvoid

This method returns an undefined value.

Whether show linker warnings or not.



17
18
19
# File 'lib/xcode_warnings/log_parser.rb', line 17

def show_linker_warnings
  @show_linker_warnings
end

Instance Method Details

#parse_build_timing_summary(text) ⇒ String

Parses the log text into a build timing summary message.

Parameters:

  • text (String)

    The text to parse.

Returns:

  • (String)

    Message of build timing summary.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/xcode_warnings/log_parser.rb', line 38

def parse_build_timing_summary(text)
  return nil unless @show_build_timing_summary

  lines = text.lines.map!(&:chomp)
  index = lines.reverse.index("Build Timing Summary")
  return nil if index.nil?

  build_times = lines[-index..-1]
    .select { |s| s =~ /.+/ }
    .reject { |s| s.include?("*") }
  total_time = build_times
    .map { |s| s.split(" | ")[1].split[0].to_f }
    .inject(:+)

  "#{build_times.join("\n")}\nTotal Build Time: **#{total_time}s**"
end

#parse_warnings(text) ⇒ Array

Parses the log text into an array of Warnings.

Parameters:

  • text (String)

    The text to parse.

Returns:

  • (Array)

    Array of ‘Warning`.



28
29
30
31
# File 'lib/xcode_warnings/log_parser.rb', line 28

def parse_warnings(text)
  warning_texts = text.each_line.select { |s| s.include?(KEYWORD_WARNING) }.uniq
  warning_texts.map! { |s| parse_warning_text(s) }.compact
end