Sha256: 66e4a5b5a55e4f9eeb2fab085bcd5e7ba6c4729b767073f8ab021387ff7e84f8

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

class String
  def squish!
    strip!
    gsub!(/\s+/, ' ')
    self
  end
  def squish
    dup.squish!
  end
  def underscore!
    self unless /[A-Z-]|::/.match?(self)
    self.to_s.gsub!("::".freeze, "/".freeze)
    self.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
    self.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
    self.tr!("-".freeze, "_".freeze)
    self.downcase!
    self
  end
  def underscore
    dup.underscore!
  end
  def camelcase!
    to_s.scan(/\w+/).collect(&:capitalize).join
  end
  def camelcase
    dup.camelcase!
  end
  def camelize!
    to_s.split(/_|\s+/).collect(&:capitalize).join
  end
  def camelize
    dup.camelize!
  end
  def safe_log_name
    self.split('::').last.underscore
  end
end
module SiteHook
  module StrExt
    def StrExt.mkvar(inspection)
      inspection.dup.to_s.tr('.', '_').tr(' ', '_')
    end
    def StrExt.mkatvar(inspection)
      inspection.dup.to_s.insert(0, '@').to_sym
    end
    def StrExt.mkatatvar(inspection)
      inspection.dup.to_s.insert(0, '@').insert(0, '@').to_sym
    end
    def StrExt.rematvar(inspection)
      inspection.dup.to_s.tr('@', '')
    end

    def self.mkmvar(inspection)
      inspection.dup.to_s.tr('@', '').to_sym
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
site_hook-1.0.30 lib/site_hook/string_ext.rb
site_hook-1.0.29 lib/site_hook/string_ext.rb
site_hook-1.0.28 lib/site_hook/string_ext.rb
site_hook-1.0.27 lib/site_hook/string_ext.rb
site_hook-1.0.26 lib/site_hook/string_ext.rb
site_hook-1.0.25 lib/site_hook/string_ext.rb
site_hook-1.0.24 lib/site_hook/string_ext.rb
site_hook-1.0.23 lib/site_hook/string_ext.rb