I'm looking for a Ruby on Rails view helper which:
- take an Array as argument
- behave like
to_sentence
(http://apidock.com/rails/Array/to_sentence) in the case the size of the Array is lower than a given parameter - behave like
pluralize
(http://apidock.com/rails/ActionView/Helpers/TextHelper/pluralize)in the case the size of the Array is lower than a given parameter
For example:
2.0.0p247 :001 > ["Audit", "Porsche", "Peugeot"].to_sentence("car", limit: 3)
=> "Audit, Porsche, and Peugeot"
2.0.0p247 :002 > ["Audit", "Porsche", "Peugeot", "Mitsubishi"].to_sentence("car", limit: 3)
=> "4 cars"
If this kind of helper doesn't exists I can create it but I would avoid to duplicate something existing.
Since the OP has asked for a one word answer, however useless that is, the answer is: