Module: StringHelper

Defined in:
lib/utils/string_helper.rb

Overview

Module StringHelper

Class Method Summary collapse

Class Method Details

.get_clear_file_path(path) ⇒ String

The method helps to replace problematic chars from string to be used as part of file path.

Parameters:

  • path (String)

Returns:

  • (String)

    path



13
14
15
# File 'lib/utils/string_helper.rb', line 13

def self.get_clear_file_path(path)
  path.to_s.gsub(/[:\/\.\*#]/, '_')
end

.get_snake_case(string) ⇒ String

The method helps to get snake case string from camel case one.

Parameters:

  • path (String)

Returns:

  • (String)

    snake_cased_string



23
24
25
26
27
28
29
# File 'lib/utils/string_helper.rb', line 23

def self.get_snake_case(string)
  string.to_s.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr('-', '_').
      downcase
end