piotrmurach / strings-case

Convert strings between different cases.
MIT License
98 stars 2 forks source link

Add ActiveSupport::Inflector Migration Guide #2

Open sshaw opened 4 years ago

sshaw commented 4 years ago

Hi,

A guide would be helpful:

etc...

piotrmurach commented 4 years ago

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

piotrmurach commented 4 years ago

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.

sshaw commented 4 years ago

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.

piotrmurach commented 3 years ago

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"