simplified regexps

This commit is contained in:
albert
2010-02-12 18:52:16 -05:00
parent 661c214094
commit caa7d8ef05
3 changed files with 4 additions and 4 deletions

View File

@@ -225,7 +225,7 @@ class Post < ActiveRecord::Base
end
def remove_favorite(user)
self.fav_string.gsub!(/fav:#{user.name}\b\s*/, " ")
self.fav_string.gsub!(/(?:\A| )fav:#{user.name}(?:\Z| )/, " ")
self.fav_string.strip!
Favorite.destroy(user, self)
end
@@ -454,7 +454,7 @@ class Post < ActiveRecord::Base
end
def remove_pool(pool)
self.pool_string.gsub!(/pool:#{pool.name}\b\s*/, " ")
self.pool_string.gsub!(/(?:\A| )pool:#{pool.name}(?:\Z| )/, " ")
self.pool_string.strip!
end
end

View File

@@ -40,7 +40,7 @@ class TagAlias < ActiveRecord::Base
def update_posts
Post.find_by_tags(antecedent_name).find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/\A#{escaped_antecedent_name} | #{escaped_antecedent_name} | #{escaped_antecedent_name}\Z/, " #{consequent_name} ").strip
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
post.update_attributes(
:tag_string => fixed_tags,
:updater_id => updater_id,

View File

@@ -69,7 +69,7 @@ class TagImplication < ActiveRecord::Base
def update_posts
Post.find_by_tags(antecedent_name).find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/\A#{escaped_antecedent_name} | #{escaped_antecedent_name} | #{escaped_antecedent_name}\Z/, " #{antecedent_name} #{descendant_names} ").strip
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{antecedent_name} #{descendant_names} ").strip
post.update_attributes(
:tag_string => fixed_tags,
:updater_id => updater_id,