J
jonsteenbergen
Sorry if this post is a duplicate, I'm having problems with my posts
posting.
Hello,
I've searched through the Ruby documentation to try and figure this
out - no luck at all, also searched google to see if anyone had
written about this. Any help or direction on where to find the answer
would be much appreciated!
This is in a rails project, but I think the answer lies in Ruby's
string methods.
I've got an object that has a list of materials attached to it, so in
my model I grab all the materials and convert them into a string -
like this:
self.materials.collect{ |x| x.material.strip.humanize.split.map{ |w|
w.capitalize}.join(' ')}.join(', ')
So I break apart each material by word, capitalize it, put that
material string back together and then join all the materials by
commas.
This works great, except that some of the materials are books with the
titles surrounded by quotes -
Book "the Snowy Day," By Ezra Jack Keats
So my code above works, except for the first letter after the initial
"
Is there a method to deal with this, so that it correctly capitalizes
the first letter after the " if there is a quote? I've tried a lot of
different things, but nothing is giving me the results I need.
Anyone have any ideas?
Thanks!
posting.
Hello,
I've searched through the Ruby documentation to try and figure this
out - no luck at all, also searched google to see if anyone had
written about this. Any help or direction on where to find the answer
would be much appreciated!
This is in a rails project, but I think the answer lies in Ruby's
string methods.
I've got an object that has a list of materials attached to it, so in
my model I grab all the materials and convert them into a string -
like this:
self.materials.collect{ |x| x.material.strip.humanize.split.map{ |w|
w.capitalize}.join(' ')}.join(', ')
So I break apart each material by word, capitalize it, put that
material string back together and then join all the materials by
commas.
This works great, except that some of the materials are books with the
titles surrounded by quotes -
Book "the Snowy Day," By Ezra Jack Keats
So my code above works, except for the first letter after the initial
"
Is there a method to deal with this, so that it correctly capitalizes
the first letter after the " if there is a quote? I've tried a lot of
different things, but nothing is giving me the results I need.
Anyone have any ideas?
Thanks!