I''m really close to solving this that I can smell it. In a nutshell
I''m
trying to create this:
http://www.baseball-reference.com/friv/link_players.cgi
I have an app that has a database of baseball players.
I''m trying to create a feature where you can copy and paste your blog
text, the feature will scan the text and return the text with the
proper html links of my app that point to the player. For example, I''m
a blog writer, I create a entry with one sentence "I am a big fan of
Derek Jeter and Jorge Posada of the Yankees" and I click submit. I want
the output to return the same sentence, but with the link of Derek Jeter
and Jorge Posada.
This is where I''m at:
#This code is taking the sentence and scanning it for two words that
are next to each other that have the first letter capitalized
@new_link_array = #this is the link data that is returned from my query
search via ferret. It will provide the proper link to the players.
@full_text = params[:q]
@full_text_array = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-Z]*)/)
@full_text_array.each_with_index do |original_name, i|
@full_text.gsub!(original_name.to_s, @new_link_array[i])
end
results = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-Z]*)/)
names_links = {}
results.each do |name|
unless names_links[name]
names_links[name] = method_to_construct_link_for_name(name)
end
end
names_links.each_pair do |name, link|
@full_text.gsub!(name, link)
end
The results are not consistent. I was wondering if somebody could help
me out.
-A
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.