Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/conductor/array.rb

Overview

Array helpers

Instance Method Summary collapse

Instance Method Details

#includes_file?(filename) ⇒ Boolean

Test if any path in array matches filename

Parameters:

  • filename (String)

    The filename

Returns:

  • (Boolean)

    whether file is found



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/conductor/array.rb', line 41

def includes_file?(filename)
  inc = false
  each do |path|
    path = path.join if path.is_a?(Array)
    if path =~ /#{Regexp.escape(filename)}$/i
      inc = true
      break
    end
  end
  inc
end

#includes_frag?(frag) ⇒ Boolean

Test if any path in an array contains any matching fragment

Parameters:

  • frag (String)

    The fragment

Returns:

  • (Boolean)

    whether fragment is found



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/conductor/array.rb', line 60

def includes_frag?(frag)
  inc = false
  each do |path|
    path = path.join if path.is_a?(Array)
    if path =~ /#{Regexp.escape(frag)}/i
      inc = true
      break
    end
  end
  inc
end

#shell_joinArray

Join components within an array

Returns:

  • (Array)

    array of strings joined by Shellwords



30
31
32
# File 'lib/conductor/array.rb', line 30

def shell_join
  map { |p| Shellwords.join(p) }
end

#symbolize_keysArray

Symbolize the keys of an array of hashes

Returns:

  • (Array)

    array of hashes with keys converted to symbols



21
22
23
# File 'lib/conductor/array.rb', line 21

def symbolize_keys
  map { |h| h.symbolize_keys }
end

#symbolize_keys!Array

Destructive version of #symbolize_keys

Returns:

  • (Array)

    symbolized arrays

See Also:



12
13
14
# File 'lib/conductor/array.rb', line 12

def symbolize_keys!
  replace symbolize_keys
end