strings-case icon indicating copy to clipboard operation
strings-case copied to clipboard

Add ActiveSupport::Inflector Migration Guide

Open sshaw opened this issue 5 years ago • 4 comments
trafficstars

Hi,

A guide would be helpful:

  • camelize(s) = Strings:Case.pascalcase(s)
  • camelize(s, :lower) = Strings::Case.camelcase(s)
  • classify(s) = Strings::Case.pascalcase(Strings::Inflection.singularize(s)) with caveats

etc...

sshaw avatar Apr 05 '20 17:04 sshaw

Great idea! Please submit PR with whatever you can translate. 🙏

piotrmurach avatar Apr 05 '20 18:04 piotrmurach

This would probably work best as a comparison table. However, strings-case is more focused and various bits will be done by other strings components which I stared documenting in the strings repository https://github.com/piotrmurach/strings.

piotrmurach avatar Apr 14 '20 11:04 piotrmurach

I have some notes but there's not much overlap really. 4 methods maybe but caveats. Here are my notes, if you want me to reformat and open a PR I will but not sure it's worthwhile:


Not quite classify, does not account for "/".

No equiv for classify because of deletetion of "/" can only do for basename of namespace

Case.pascalcase("foo bar", :separator => "::")
Strings::Case.pascalcase(Strings::Inflection.singularize(name))

camelize = pascalcase
camelize(:lower) = camelcase
titlecase = humanize

Sorta, no inflections


Strings::Numeral.ordinalize(:short => true)  = ordinalize

ordinal has no equiv.

sshaw avatar Apr 15 '20 23:04 sshaw

I will add a comprehensive migration guide in the strings project itself when all the gems are updated. My goal is to achieve as much compatibility as possible to make it easy for people to transition.

For this gem, these should be equivalent:

Strings::Case ActiveSupport
sentencecase humanize
titlecase titleize
snakecase underscore
pascalcase camelize
camelcase camelize(false)
dashcase dasherize

What remains to do is to ensure that by default the / and :: are handled the same way:

Strings::Case.snakecase("HTTP::StatusCode") # => "http/status_code"
Strings::Case.camelcase("http/status_code")  #=> "HTTP::StatusCode"

piotrmurach avatar Feb 01 '21 22:02 piotrmurach