Module: MinitestBender::Utils

Defined in:
lib/minitest-bender/utils.rb

Class Method Summary collapse

Class Method Details

.english_join(strings) ⇒ Object



17
18
19
# File 'lib/minitest-bender/utils.rb', line 17

def self.english_join(strings)
  strings.reject(&:empty?).join(', ').gsub(/(.*), /, '\1 and ')
end

.relative_path(full_path) ⇒ Object



5
6
7
# File 'lib/minitest-bender/utils.rb', line 5

def self.relative_path(full_path)
  full_path.gsub("#{Dir.pwd}/", '')
end

.with_home_shorthand(full_path) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/minitest-bender/utils.rb', line 9

def self.with_home_shorthand(full_path)
  if ENV['HOME'].to_s.start_with?('/home/')
    full_path.sub(ENV['HOME'], '~')
  else
    full_path
  end
end

.with_symbolized_keys(hash) ⇒ Object



21
22
23
24
25
# File 'lib/minitest-bender/utils.rb', line 21

def self.with_symbolized_keys(hash)
  hash.each_with_object({}) do |(k, v), h|
    h[k.to_sym] = v
  end
end

.without_nil_values(hash) ⇒ Object



27
28
29
30
31
# File 'lib/minitest-bender/utils.rb', line 27

def self.without_nil_values(hash)
  hash.each_with_object({}) do |(k, v), h|
    h[k] = v unless v.nil?
  end
end