On Dec 10, 10:53 am, "William James" <w_a_x_... / yahoo.com> wrote:
> Jason  Vogel wrote:
> > William,
>
> > This is exactly what I'm looking for.  I don't understand it, but it's
> > what I'm looking for.
>
> > Would you mind explaining what your code does?
>
> > Thanks,
> > Jason
>
> > On Dec 8, 8:23 pm, "William James" <w_a_x_... / yahoo.com> wrote:
> > > Jason  Vogel wrote:
> > > > Disclaimer : Ruby Nuby and I don't know RegEx basically at all.  I know
> > > > RegEx is the answer, just don't know where to start.
>
> > > > Current Source:
> > > >    str.split(' ').each {|w| w.capitalize!}.join(' ')
>
> > > > Text:
> > > >    ADDITIONAL SPA (ONLY AVAILABLE W/PURCHASE OF POOL OR SPA)
> > > >    SELLER HEAT/AC/DUCTWORK
>
> > > > Result:
> > > >    Additional Spa (only Available W/purchase Of Pool Or Spa)
> > > >    Seller Heat/ac/ductwork
>
> > > > Desired:
> > > >    Additional Spa (Only Available w/Purchase of Pool or Spa)
> > > >    Seller Heat/AC/Ductwork
>
> > > > Isssus:
> > > >   - Need to capitalize after a "/'
> > > >   - Need specific word case handling (e.g. "Ac" => "AC","or" => "or",
> > > > "w/[a]" => "w/[A]")
>
> > > > Thanks,
> > > > Jasonspecials = %w( of or w AC ).
> > > inject({}){|h,s| h.update({s.downcase,s}) }
>
> > > puts DATA.read.downcase.split( /([^a-z]+)/ ).map{|s|
> > >   specials[s] or s.capitalize }.join
>
> > > __END__
> > > ADDITIONAL SPA  (ONLY AVAILABLE W/PURCHASE OF POOL OR SPA)
> > > SELLER HEAT/AC/DUCTWORK
>
> > > ---  output  -----
> > > Additional Spa  (Only Available w/Purchase of Pool or Spa)
> > > Seller Heat/AC/DuctworkIt helps to inspect the data structures.
>
> Try:
>
> specials = %w( of or w AC ).
> inject({}){|h,s| h.update({s.downcase,s}) }
>
> p specials
>
> text = DATA.read.downcase
> p text.split( /([^a-z]+)/ )
> puts text.split( /([^a-z]+)/ ).map{|s|
>   specials[s] or s.capitalize }.join
>
> __END__
> ADDITIONAL SPA  (ONLY AVAILABLE W/PURCHASE OF POOL OR SPA)
> SELLER HEAT/AC/DUCTWORK

Paul and William,

Thank you both for taking the time to respond and explain.  I really
appreciate it.

Thanks,
Jason