Module: Legion::Extensions::Exec::Helpers::ResultParser

Defined in:
lib/legion/extensions/exec/helpers/result_parser.rb

Class Method Summary collapse

Class Method Details

.parse_git_status(output) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/legion/extensions/exec/helpers/result_parser.rb', line 39

def parse_git_status(output)
  modified   = []
  untracked  = []
  deleted    = []

  output.each_line do |line|
    code = line[0..1].strip
    file = line[3..].strip

    case code
    when 'M', 'MM', 'AM'
      modified << file
    when '??'
      untracked << file
    when 'D', 'MD'
      deleted << file
    end
  end

  {
    clean:     modified.empty? && untracked.empty? && deleted.empty?,
    modified:  modified,
    untracked: untracked,
    deleted:   deleted
  }
end

.parse_rspec(output) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/exec/helpers/result_parser.rb', line 10

def parse_rspec(output)
  examples = 0
  failures = 0
  pending  = 0

  if (match = output.match(/(\d+)\s+examples?,\s+(\d+)\s+failures?/))
    examples = match[1].to_i
    failures = match[2].to_i
  end

  if (match = output.match(/(\d+)\s+pending/))
    pending = match[1].to_i
  end

  { examples: examples, failures: failures, pending: pending, passed: failures.zero? }
end

.parse_rubocop(output) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/legion/extensions/exec/helpers/result_parser.rb', line 27

def parse_rubocop(output)
  files    = 0
  offenses = 0

  if (match = output.match(/(\d+)\s+files?\s+inspected,\s+(\d+)\s+offenses?\s+detected/))
    files    = match[1].to_i
    offenses = match[2].to_i
  end

  { files: files, offenses: offenses, clean: offenses.zero? }
end