Class: String

Inherits:
Object
  • Object
show all
Includes:
StringExtensions
Defined in:
lib/rails_extensions/string.rb

Defined Under Namespace

Modules: StringExtensions

Instance Method Summary collapse

Methods included from StringExtensions

#pluralize

Instance Method Details

#normalize_string(regex = /[^\w.]/, replacement = ' ') ⇒ Object



2
3
4
5
6
7
# File 'lib/rails_extensions/string.rb', line 2

def normalize_string(regex = /[^\w.]/, replacement = ' ')
  I18n.transliterate(self)
      .gsub(regex, replacement)
      .squish
      .downcase
end

#pluralizes(count) ⇒ Object



13
14
15
16
17
# File 'lib/rails_extensions/string.rb', line 13

def pluralizes(count)
  split(' ')
    .map { |s| s.pluralize(count) }
    .join(' ')
end

#strict_normalize_stringObject



9
10
11
# File 'lib/rails_extensions/string.rb', line 9

def strict_normalize_string
  normalize_string(/[^A-Za-z0-9]/, '')
end

#true?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rails_extensions/string.rb', line 19

def true?
  to_s.downcase == 'true'
end