Module: Gnurr::Helper

Included in:
CLI, Git, Linter, Processor
Defined in:
lib/gnurr/helper.rb

Overview

Miscellaneous helper methods for the gem

Instance Method Summary collapse

Instance Method Details

#array_to_ranges(array) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gnurr/helper.rb', line 6

def array_to_ranges(array)
  array = array.compact.uniq.sort
  ranges = []
  return ranges if array.empty?
  left = array.first
  right = nil
  array.each do |obj|
    if right && obj != right.succ
      ranges << Range.new(left, right)
      left = obj
    end
    right = obj
  end
  ranges + [Range.new(left, right)]
end

#escaped_filename(filename) ⇒ Object



27
28
29
# File 'lib/gnurr/helper.rb', line 27

def escaped_filename(filename)
  filename.gsub(/(\s)/,'\\\\\1')
end

#left_bump(indent = 1) ⇒ Object



31
32
33
# File 'lib/gnurr/helper.rb', line 31

def left_bump(indent = 1)
  ''.ljust(indent * 2).colorize(color: color)
end

#log_error(e) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/gnurr/helper.rb', line 35

def log_error(e)
  if @options[:stdout]
    puts "#{'ERROR'.colorize(:red)}: #{e}"
    puts e.backtrace if @options[:verbose]
  else
    warn("Error: #{e}")
  end
end

#severity_color(violations, files) ⇒ Object



22
23
24
25
# File 'lib/gnurr/helper.rb', line 22

def severity_color(violations, files)
  return :green if violations.zero? || files.zero?
  violation_count / files < 1 ? :yellow : :red
end