module MinitestBender::Utils
Public Class Methods
english_join(strings)
click to toggle source
# File lib/minitest-bender/utils.rb, line 17 def self.english_join(strings) strings.reject(&:empty?).join(', ').gsub(/(.*), /, '\1 and ') end
first_line(string)
click to toggle source
# File lib/minitest-bender/utils.rb, line 21 def self.first_line(string) string.split("\n").first.to_s end
relative_path(full_path)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/minitest-bender/utils.rb, line 25 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)
click to toggle source
# File lib/minitest-bender/utils.rb, line 31 def self.without_nil_values(hash) hash.each_with_object({}) do |(k, v), h| h[k] = v unless v.nil? end end