The 'auto' button now takes the name and creates a tag for it. So:
Name: The Best Player in the World is from a City in an Arboretum
Becomes:
Tag: player_best_player_world_city_arboretum
So the tag is based on the type of object, plus a scaled down version of the name. As you no doubt noticed, I took out a bunch of connector words there (mainly articles). This involved regular expressions.
At first, I was doing something like this:
name.gsub!(/\sthe\s/,' ')
name.gsub!(/\sa\s/,' ')
name.gsub!(/\san\s/,' ')
Yes, I had one line for each thing I wanted to remove, which is of course silly. So I made a list of all the excluded words and tried again, only I ran into a problem. It's not a string I'm using for matching here, it's a regular expression - meaning I couldn't just throw the current loop value in the middle and expect it to work!
Luckily, there's a way to do exactly that:
exclusions.each do |x|
excludeMiddle = Regexp.new("\s#{x}\s")
name.gsub!(excludeMiddle,' ')
end
Regexp.new takes a string, from which it'll create a regular expression. And I can do all the manipulating I want within strings!
Also I made a few more planets using the new autotagging feature. But that's not as exciting.
No comments:
Post a Comment