Commit Graph

61 Commits

Author SHA1 Message Date
fatkodima
e3c546eb0c Fix humanize for strings ending with id 2023-05-31 02:16:37 +03:00
Quentin "Thornolf" Baudet
86faeb8386
Fix (Inflector::Methods#underscore): small regression 2021-10-28 00:25:09 +02:00
Jean Boussier
bade613012 Make sure Inflector.underscore returns a String
If you were to pass it an underscore symbol, it
would be immediately returned without modification.
2021-04-08 16:26:45 +02:00
Jean Boussier
dd5b00cd6c Fix the underscore inflector optimization
It introduced a regression for strings with a group of exactly
two capital letters.
2021-02-09 16:37:45 +01:00
Ryuta Kamizono
76ae3dbed3 Revert "Merge pull request #22780 from pauloancheta/master"
This reverts commit 7aa047b57237f691540afc3e22b91f73df7e5bc4, reversing
changes made to c9b36dd67a1c8fe40ad76301e3929e47b0b23e1d.

This is a right example for singular names.
2020-02-13 11:41:15 +09:00
Alberto Rocha
892c30d025 Fix titleize to work with parentheses (#37029)
* Fix titleize to work with parentheses

* Add extra test case

* Update code to also ignore the ')' character and add a test case
2019-08-24 03:10:47 +02:00
Pierre Hedkvist
1ede346975 Fixed typo in test for activesupport parameterize 2017-11-01 10:27:29 +00:00
Koichi ITO
ac717d65a3 [Active Support] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
72950568dd Use frozen-string-literal in ActiveSupport 2017-07-09 15:08:29 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Rafael Mendonça França
0875256fe9
Merge pull request #28480 from mubashirhanif/add_keep_id_suffix_option_to_humanize_new
Add keep id suffix option to humanize new
2017-03-28 17:57:17 -04:00
Mubashir Hanif
f0c8f1b085 Added options hash to titleize method and keep_id_suffix option to humanize
some documentation

remove extra whitespace.

Added id in the middle test case and corrected some testcases.

Some Coding standard guidelines corrections as suggested by codeclimate.

Some more corrections suggested by codeclimate.
2017-03-21 22:55:17 +01:00
Andrew White
48b37f127f Update titlelize regex to allow apostrophes
In 4b685aa the regex in `titlelize` was updated to not match
apostrophes to better reflect the nature of the transformation.
Unfortunately this had the side effect of breaking capitalization
on the first word of a sub-string, e.g:

  >> "This was 'fake news'".titleize
  => "This Was 'fake News'"

This is fixed by extending the look-behind to also check for a
word character on the other side of the apostrophe.

Fixes #28312.
2017-03-06 17:51:03 +00:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02:00
Xavier Noria
5c315a8fa6 modernizes hash syntax in activesupport 2016-08-06 19:38:33 +02:00
Xavier Noria
a731125f12 applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:10:53 +02:00
Rafael Mendonça França
1a4deb9664
Merge pull request #19428 from bdmac/fix_safe_buffer_titleize
Fixes Inflector#titleize to work with SafeBuffer
2016-05-18 18:21:16 -03:00
Swaathi K
c9143e15a1 Parameterize with options to preserve case of string
Added test cases

Using kwargs instead of three seperate functions

Updated parameterize in transliterate.rb

Updated parameterize in transliterate.rb

Added deprecation warnings and updating RDoc+Guide

Misspelled separtor. Fixed.

Deprecated test cases and added support to parameterize with keyword parameters

Squashing commits.

Fixed test cases and added deprecated test cases

Small changes to Gemfile.lock and CHANGELOG

Update Gemfile.lock
2015-11-07 16:57:04 +05:30
Akira Matsuda
c971bc0568 ✂️ empty line at the top of files 2015-09-21 01:27:33 +09:00
Brian McManus
792f625bec Fixes Inflector#titleize to work with SafeBuffer
The way Inflector#titleize was implemented did not work properly when
called on a SafeBuffer object. Using the global `$&` variable in the
gsub resulted in calling capitalize on a nil object for reasons I still
do not fully understand. Removing the UNSAFE_STRING_METHODS override for
the gsub method in SafeBuffer "fixed" the bug but is obviously
unacceptable.

An example of this is very easy to see in rails console:

    ActiveSupport::SafeBuffer.new("my test").titleize
    > NoMethodError: undefined method `capitalize' for nil:NilClass

Using the non global version of gsub with a |match| arg passed to the
block fixes the problem. Again I do not quite understand why. I noticed
that other parts of Inflector were already using the standard block arg
version of gsub so I don't think it should be a problem to convert this
method to using it as well.
2015-03-20 10:28:25 -07:00
Vipul A M
6eced6a1fe Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 onwards. 2015-02-03 20:51:40 +05:30
Matthew Draper
ccbb48196e Fix for inflector's incorrect camelCase replacement for acronyms
Fixes #8015, #9756.

[Fred Wu & Matthew Draper]
2014-09-06 04:56:25 +09:30
Xavier Noria
daaa21bc7d several enhancements to humanize [closes #12288]
* Strips leading underscores.
* Changes some unnecessary gsub!s to sub!s.
* Replaces some anchors ^, $ with \A, \z.
* Documents that human inflection rules are applied.
* Documents that words are downcased except acronyms.
* Adds an example with an acronym.
* Rewords docs.
2014-05-06 21:35:40 +02:00
Robin Dupret
686e820c48 Add a comment to ensure that a test won't be removed [ci skip]
The 'cow' => 'kine' inflection has gone with c300dca9 but it should
not be removed from the tested irregularities since it ensures that
inflections work with words that do not begin with the same letters.
2014-03-03 14:15:59 +01:00
Lihan Li
534b36093d wrap test that changes inflections in with_dup 2013-11-28 12:35:20 -05:00
claudiob
c61544c781 Add +capitalize+ option to Inflector.humanize
So strings can be humanized without being capitalized:

    'employee_salary'.humanize                    # => "Employee salary"
    'employee_salary'.humanize(capitalize: false) # => "employee salary"
2013-11-06 13:03:46 -08:00
Andrew White
2d53ee0f42 Don't mutate the original inflections instance in the tests 2013-07-30 12:01:56 +01:00
Juanjo Bazán
ef4ac7a489 Inflector irregular singularize rules 2013-01-01 12:50:00 +01:00
Godfrey Chan
fe933be5e2 Adds missing inflector tests to ensure idempotency
This is a follow up to #4719. It appears that singularize and pluralize
are supposed to be idempotent - i.e. when you call singularize or
pluralize multiple times on the same string, you should get the same
result. (At least for the "officially supported" cases that the stock
inflector is designed to handle.) #4719 added the missing tests for
regular cases, and this commit added the missing tests for the
irregularities.

While I'm at that, I also synced up the irregularity test cases with
the current set of irregularity cases that we ship out-of-the-box.
2012-06-21 02:16:48 -07:00
Anuj Dutta
bc51ad957a Fix an issue with inflection where my_analyses (in plular form) incorrectly converted to my_analyasis(in singular form). 2012-05-16 22:58:03 +01:00
José Valim
66c5ac3be9 Merge pull request #5177 from cap10morgan/fix-gh-issue-4374
fix inflector bug where -ice gets singularized into -ouse
2012-04-30 00:13:40 -07:00
Xavier Noria
206974a97c adds a new test case for titleize 2012-04-08 01:10:08 +02:00
Xavier Noria
4b685aad7b revises the regexp used in titleize
The regexp used in titleize matches saxon genitive
and other contractions, only to call capitalize on
the captured text and have the apostrophe upcased
which yields the apostrophe itself. It is more
clear that the regexp matches just what it has to
match.
2012-04-07 23:58:44 +02:00
Vasiliy Ermolovich
633ee64e20 String#titleize works properly with smart quotes, closes #5584 2012-03-26 21:18:25 +03:00
Wes Morgan
16e7f2f809 fix inflector bug where -ice gets pluralized into -ouse
This should happen for mouse or louse, but not slice or pumice.
2012-02-25 14:22:15 -07:00
Xavier Noria
fd5d9b366c fixes a regression introduced by 532cd4, and a bogus test in AP the regression uncovered 2012-02-10 22:17:30 -08:00
Mark Rushakoff
6f253fb440 Fix inflection regexes for mouse, mice 2011-12-07 23:14:02 -08:00
Pavan Kumar Sunkara
1934b77406 Added the test case for #3537 2011-11-06 19:22:46 +05:30
José Valim
6b010c2690 Revert removing gsub and sub from safe buffer. 2011-09-08 20:54:30 +02:00
Damien Mathieu
3718ccd2a6 remove support of symbols on classify and camelize 2011-09-08 10:22:21 +02:00
Arun Agrawal
4700e1fe6e StringToParameterizeWithNoSeparator: dashed parameter will not
change.
2011-06-25 06:17:00 +05:30
David Lee
f3e8bb8394 Test retain delimiter in parameterization inflector 2011-06-11 01:35:16 -07:00
Jason
3880ab0d7c ordinalize negative numbers patch
Applied patch by Amir Manji
  https://github.com/rails/rails/issues/437#issuecomment-1116045

Signed-off-by: Jason <jasonmichaelroth@gmail.com>
2011-05-07 13:21:00 -06:00
Dan Pickett
1754bd9b20 handle double pluralization for irregular plurals
[#6363]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-16 15:08:25 -02:00
Norman Clarke
dceef0828a Improve reliability of Inflector.transliterate. [#4374 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-12 23:19:39 -07:00
Rolf Bjaanes
4eab983b95 Changed the way inflections for uncountables work for 'funky jeans' [#3576 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-05 23:54:42 +02:00
Kristopher Murata
ef84e691ff Parameterize should accept malformed utf8 characters [#4323 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-04 09:37:26 -07:00
wycats
7a83abe52f Any reason we can't just use the slow 1.8 path for transliteration in 1.9? 2010-03-17 00:54:42 -07:00