Module: Ftpmock::StringUtils

Defined in:
lib/ftpmock/utils/string_utils.rb

Class Method Summary collapse

Class Method Details

.all_present?(*strings) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/ftpmock/utils/string_utils.rb', line 7

def all_present?(*strings)
  strings.all? { |string| present?(string) }
end

.diff(localfile, path) ⇒ Object



25
26
27
# File 'lib/ftpmock/utils/string_utils.rb', line 25

def diff(localfile, path)
  Diffy::Diff.new(localfile.to_s, path.to_s, source: 'files').to_s(:color)
end

.parameterize(string, separator: '-') ⇒ Object

Inspired by from gems/activesupport-5.2.3 /lib/active_support/inflector/transliterate.rb



19
20
21
22
23
# File 'lib/ftpmock/utils/string_utils.rb', line 19

def parameterize(string, separator: '-')
  string.to_s
        .gsub(/[^a-z0-9\-_]+/i, separator)
        .downcase
end

.present?(string) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/ftpmock/utils/string_utils.rb', line 11

def present?(string)
  return string.present? if string.respond_to?(:present?)

  !string.to_s.strip.empty?
end