module CoreExtensions::String

STRING ##########################################################################################

BOOLEAN #########################################################################################

Constants

LSTRIP_SPACE_REGEX
RSTRIP_SPACE_REGEX
SPACE_CHAR_CLASS

en.wikipedia.org/wiki/Whitespace_character#Unicode

Public Instance Methods

force_utf8() click to toggle source
# File lib/core_ext.rb, line 38
def force_utf8
  if (encoding == Encoding::UTF_8) && valid_encoding?
    self
  else
    encode('utf-8', invalid: :replace, undef: :replace)
  end
end
lstrip() click to toggle source
Calls superclass method
# File lib/core_ext.rb, line 13
def lstrip
  (encoding == Encoding::UTF_8) ? sub(LSTRIP_SPACE_REGEX, '') : super
end
possessive() click to toggle source
# File lib/core_ext.rb, line 32
def possessive
  str = self + "'"
  str += 's' unless %r{(s|se|z|ze|ce|x|xe)$}i.match(self)
  str
end
rstrip() click to toggle source
Calls superclass method
# File lib/core_ext.rb, line 17
def rstrip
  (encoding == Encoding::UTF_8) ? sub(RSTRIP_SPACE_REGEX, '') : super
end
strip() click to toggle source
Calls superclass method
# File lib/core_ext.rb, line 21
def strip
  if encoding == Encoding::UTF_8
    dup.tap do |str|
      str.sub!(LSTRIP_SPACE_REGEX, '')
      str.sub!(RSTRIP_SPACE_REGEX, '')
    end
  else
    super
  end
end
to_bool(default = nil) click to toggle source
# File lib/core_ext.rb, line 176
def to_bool(default = nil)
  return true  if %w(true  1 yes on  t).include?(self.downcase.strip)
  return false if %w(false 0  no off f).include?(self.downcase.strip)
  default
end
to_hex() click to toggle source
# File lib/core_ext.rb, line 46
def to_hex
  self.b.unpack('H*').first
end