Sha256: 65b5d3693a57d3a4f4f3d2b20f3d4ff206223a5364abfe24b2d2d15fb7cf1f9b

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

class String
  def parameterize
    self.downcase.strip.gsub(/\W+/, '-')
  end

  def dasherize
    `#{self}.replace(/[-_\s]+/g, '-')
            .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1-$2')
            .replace(/([a-z\d])([A-Z])/g, '$1-$2')
            .toLowerCase()`
  end

  def demodulize
    %x{
      var idx = #{self}.lastIndexOf('::');

      if (idx > -1) {
        return #{self}.substr(idx + 2);
      }

      return #{self};
    }
  end

  def underscore
    `#{self}.replace(/[-\s]+/g, '_')
    .replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2')
    .replace(/([a-z\d])([A-Z])/g, '$1_$2')
    .replace(/-/g, '_')
    .toLowerCase()`
  end

  def camelize(first_letter = :upper)
    `#{underscore}.replace(/(^|_)([^_]+)/g, function(match, pre, word, index) {
      var capitalize = #{first_letter} === #{:upper} || index > 0;
      return capitalize ? word.substr(0,1).toUpperCase()+word.substr(1) : word;
    })`
  end
  alias_method :camelcase, :camelize
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-activesupport-0.1.0 opal/active_support/core_ext/string.rb