Trying to create a titleize method manually

Seems to me we went around on this last March. Here’s my little ditty
from that time: GitHub - tamouse/titlecase: Add titlecase methods to String

On Fri, Aug 30, 2013 at 1:32 AM, Tamara T. [email protected]
wrote:

Seems to me we went around on this last March. Here’s my
little ditty from that time: GitHub - tamouse/titlecase: Add titlecase methods to String

Interesting! I haven’t had cause to use the block-form of gsub
before, and here you are, using it twice. I’ll have to remember that
trick!

One question though: if it’s multiple lines, your gem will uppercase
the first char of every line. Was that your intent? If not, you can
use \A instead of ^.

-Dave

tamouse m. wrote in post #1120041:

Seems to me we went around on this last March. Here’s my little ditty
from that time: GitHub - tamouse/titlecase: Add titlecase methods to String

Very succinct! I like the way you used send :include.
I forgot you could do this: “stopwords=DEFAULT_STOP_WORDS”. That would
have made my code a bit neater :slight_smile:

Dave A. wrote in post #1120093:

Interesting! I haven’t had cause to use the block-form of gsub
before, and here you are, using it twice. I’ll have to remember that
trick!

I already showed you that! :stuck_out_tongue:

Joel P. wrote in post #1119780:

def titleize( x )
x.gsub( /\w+/ ) { |w| w.length > 3 ? w.capitalize : w.downcase
}.capitalize
end

Speaking of using gsub with a block, Bozhidar Batsov JUST wrote a blog
post about it:

Using Ruby’s gsub with a block - (think)

On Aug 30, 2013, at 8:49 AM, Dave A.
[email protected] wrote:

the first char of every line. Was that your intent? If not, you can
use \A instead of ^.

Actually, I had no thoughts around multiple lines at all. It’s an
interesting question which way to go with that. Maybe I should offer an
option?

Technically an explicit newline should be followed by a capital letter,
regardless of the preceding punctuation. This is true in poetry, and as
far as I know, everywhere else. “Word wrap” doesn’t count as that’s down
to the editor.

On Aug 30, 2013, at 11:06 AM, Joel P. [email protected] wrote:

Technically an explicit newline should be followed by a capital letter,
regardless of the preceding punctuation. This is true in poetry, and as
far as I know, everywhere else. “Word wrap” doesn’t count as that’s down
to the editor.

I am aware of poetry style, but that also doesn’t titlecase each word in
the line. P’raps I should consult my favourite grammarians on this.

On Aug 30, 2013, at 10:49 AM, Tamara T. [email protected]
wrote:

On Aug 30, 2013, at 8:49 AM, Dave A. [email protected] wrote:

One question though: if it’s multiple lines, your gem will uppercase
the first char of every line. Was that your intent? If not, you can
use \A instead of ^.

Actually, I had no thoughts around multiple lines at all. It’s an interesting
question which way to go with that. Maybe I should offer an option?

Well, after consulting with my grammarian pals, I have a new concern.
The multi-line thing is not really the issue, per se (except that I
should not assume a new line begins a sentence). The issue is what to do
after certain punctuation marks:

  • sentence ending marks: capitalize next letter
  • certain fragment ending marks such as the colon, dash, and so on:
    capitalize next letter, maybe? (i.e. what follows is considered a
    subtitle). Example: “Quiet: The Power of Introverts in a World That
    Can’t Stop Talking” the current implementation would render the “The”
    following that colon in lower case. Clearly incorrect.

Let’s not even get started with I18n issues