Module: Herdic::Util

Defined in:
lib/herdic/util.rb

Constant Summary collapse

COLORS =
{
  black:   0,
  red:     1,
  green:   2,
  yellow:  3,
  blue:    4,
  magenta: 5,
  cyan:    6,
  white:   7,
}

Class Method Summary collapse

Class Method Details

.color(str, c) ⇒ Object



39
40
41
# File 'lib/herdic/util.rb', line 39

def color(str, c)
  "\e[1;#{30+COLORS[c]}m#{str}\e[0m"
end

.find_files_upward(filename, base, count = 0) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/herdic/util.rb', line 8

def find_files_upward(filename, base, count = 0)
  found = []
  found_count = 0

  while count == 0 || found_count <= count
    file = File.join base, filename

    if File.exists? file
      found << file
      found_count += 1
    end

    break if '.' == base || '/' == base

    base = File.dirname base
  end

  found
end