class Porch::CoreExt::String

Constants

CAPITALIZE_SEPARATOR
CLASSIFY_SEPARATOR
NAMESPACE_SEPARATOR
UNDERSCORE_DIVISION_TARGET
UNDERSCORE_SEPARATOR

Attributes

string[R]

Public Class Methods

new(string) click to toggle source
# File lib/porch/core_ext/string.rb, line 10
def initialize(string)
  @string = string.to_s
end

Public Instance Methods

==(other) click to toggle source
# File lib/porch/core_ext/string.rb, line 45
def ==(other)
  to_s == other
end
Also aliased as: eql?
capitalize() click to toggle source
# File lib/porch/core_ext/string.rb, line 14
def capitalize
  head, *tail = underscore.split(CLASSIFY_SEPARATOR)

  self.class.new tail.unshift(head.capitalize).join(CAPITALIZE_SEPARATOR)
end
eql?(other)
Alias for: ==
gsub(pattern, replacement=nil, &blk) click to toggle source
# File lib/porch/core_ext/string.rb, line 20
def gsub(pattern, replacement=nil, &blk)
  if block_given?
    string.gsub(pattern, &blk)
  else
    string.gsub(pattern, replacement)
  end
end
split(pattern, limit=0) click to toggle source
# File lib/porch/core_ext/string.rb, line 28
def split(pattern, limit=0)
  string.split(pattern, limit)
end
to_s() click to toggle source
# File lib/porch/core_ext/string.rb, line 32
def to_s
  string
end
underscore() click to toggle source
# File lib/porch/core_ext/string.rb, line 36
def underscore
  new_string = gsub(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
  new_string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
  new_string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
  new_string.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
  new_string.downcase!
  self.class.new new_string
end