rsl / stringex

Some [hopefully] useful extensions to Ruby’s String class. It is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class].
MIT License
984 stars 158 forks source link

"dot" used for abbreviations #65

Closed minaguib closed 11 years ago

minaguib commented 12 years ago

I understand the reasoning behind something like "google.com" -> "google dot com"

However, I feel that for abbreviations, "D.N.A." would be better converted to "dna"

Yay/nay ? I'd be happy to work on and submit a patch.

rsl commented 12 years ago

hrm that's actually a really good idea. on vacation at the moment. won't be back til like... october really. happy to get something like this though. unsure about edge cases but yeah as is isn't optimal.

minaguib commented 12 years ago

Cool. I'll whip something up.

minaguib commented 12 years ago

Question for discussion.

Currently, there's some unpredictable behavior for dot handling:

irb(main):012:0> "a.b".to_url
=> "a-dot-b"
irb(main):013:0> "a.b.c".to_url
=> "a-dot-b-c"

Is this intentional or buggy ? I came across it in my own branch which implements handling for abbreviations:

irb(main):004:0> "Match the D.N.A.".to_url
=> "match-the-dna"

irb(main):005:0> "Go to the Y.M.C.America".to_url
=> "go-to-the-y-dot-m-c-dot-america"

How do you think that last example would be best URLified ?

rsl commented 12 years ago

first should be a-dot-b-dot-c. definitely bug. YMCAmerica is prolly just that. i've only heard it called YMCA mostly though. but i guess it's the same pattern with the word spelled out too, yeah?

ehoch commented 12 years ago

@minaguib Still working on this? Would love a fix...

rsl commented 11 years ago

@minaguib i'm back from vacation land if i can pitch on this. trying to get some improvements into Stringex lately and this one is definitely one i'd love to have in the next gem release [prolly next week]. lemme know if there's anything i can do to help or whatever.

minaguib commented 11 years ago

Hey

I've had this https://github.com/minaguib/stringex/commit/d36c35273b318d44909b2285b683553571d2edc0 done for a while.

As you can see it's much better than before, however since I discovered the anomaly (as posted above in the discussion and added explicitly in the test suite "Go to the Y.M.C.America"), I haven't had time to go back and fix that case in the old code.

Unfortunately I won't have time the next few days to work on it. If anyone would like to attack the anomaly I pointed out you're more than welcome to.

rsl commented 11 years ago

i'll pull this into a branch and mess around with getting that bug out. awesome.

rsl commented 11 years ago

is this the expected transliteration for you?

  "Go to the Y.M.C.America" =>
    "go-to-the-ymcamerica",

i've got passing tests on that if so ready to go.

rsl commented 11 years ago

if not... oh boy ;)

rsl commented 11 years ago

check out https://github.com/rsl/stringex/tree/dotbug if you want to play around with it. or lemme know if it's mergeable. would love to push it to master.

rsl commented 11 years ago

gonna go ahead and merge this. seems as good as anything. could go back and forth on how that should go. thanks on this.