Class: String

Inherits:
Object show all
Defined in:
lib/eluvia/utils/string.rb

Instance Method Summary collapse

Instance Method Details

#ltrim(chars = "\s") ⇒ Object

Remove characters from string on the left side



22
23
24
# File 'lib/eluvia/utils/string.rb', line 22

def ltrim(chars = "\s")
  self.sub(/^[#{Regexp.escape(chars)}]*/, "")
end

#rtrim(chars = "\s") ⇒ Object

Remove characters from string on the right side



27
28
29
# File 'lib/eluvia/utils/string.rb', line 27

def rtrim(chars = "\s")
  self.sub(/[#{Regexp.escape(chars)}]*$/, "")
end

#to_filenameObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/eluvia/utils/string.rb', line 3

def to_filename
  result = self
  result = I18n.transliterate(result)
  result
    .downcase
    .gsub(/[^a-z0-9.\s,\-_]/, "")
    .gsub(/[.\s,\-_]+/, "-")
    .sub(/^-*/, "")
    .sub(/-*$/, "")
end

#trim(chars = "\s") ⇒ Object

Remove characters from string on the left and right side



15
16
17
18
19
# File 'lib/eluvia/utils/string.rb', line 15

def trim(chars = "\s")
  self
    .sub(/^[#{Regexp.escape(chars)}]*/, "")
    .sub(/[#{Regexp.escape(chars)}]*$/, "")
end