Sha256: 8c9393ed7b0d49d3540e85b271ab5af7005d4dbe07a4590df658b7b37c17800e
Contents?: true
Size: 803 Bytes
Versions: 3
Compression:
Stored size: 803 Bytes
Contents
# frozen_string_literal: false require 'forwardable' # reverting to StringExtra class, from a module with String refinements class StringExtra extend Forwardable def_delegators(:@str, :upcase, :capitalize, :length, :downcase, :gsub) def initialize(str) @str = str end def titleize underscore .gsub(/_id$/, '').tr('_', ' ').capitalize .gsub(/\b([a-z])/) { Regexp.last_match[1].capitalize } end def humanize gsub(/_id$/, '').tr('_', ' ').capitalize end def camelize gsub(%r{/\/(.?)/}) { '::' + Regexp.last_match[1].upcase } .gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase } end def underscore gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jruby_art-1.2.1 | lib/jruby_art/helpers/string_extra.rb |
jruby_art-1.2.0.pre | lib/jruby_art/helpers/string_extra.rb |
jruby_art-1.1.3 | lib/jruby_art/helpers/string_extra.rb |