Module: Gemmy::Patches::StringPatch::InstanceMethods::Alpha

Defined in:
lib/gemmy/patches/string_patch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._alpha(string, bang: false, strip_whitespace: false) ⇒ Object



46
47
48
49
50
# File 'lib/gemmy/patches/string_patch.rb', line 46

def self._alpha(string, bang: false, strip_whitespace: false)
  fn = bang ? :gsub! : :gsub
  regex = /[^a-zA-Z0-9#{'\s' unless strip_whitespace}]/
  string.send fn, regex, ''
end

Instance Method Details

#alpha(opts = {}) ⇒ Object

Gsub non-alphabetical characters



58
59
60
61
62
63
# File 'lib/gemmy/patches/string_patch.rb', line 58

def alpha(opts={})
  Gemmy.patch("string/i/alpha")._alpha(
    self,
    opts
  )
end

#alpha!(opts = {}) ⇒ Object



51
52
53
54
55
56
# File 'lib/gemmy/patches/string_patch.rb', line 51

def alpha!(opts={})
  Gemmy.patch("string/i/alpha")._alpha(
    self,
    opts.merge(bang: true)
  )
end