Commit 117acdd1 authored by Maxwell Salzberg's avatar Maxwell Salzberg

move mention regex to a constant in mention

parent 718c4fd3
......@@ -3,6 +3,8 @@
# the COPYRIGHT file.
class Mention < ActiveRecord::Base
REGEX = /@\{([^;]+); ([^\}]+)\}/
belongs_to :post
belongs_to :person
validates :post, :presence => true
......
......@@ -85,8 +85,7 @@ class StatusMessage < Post
end
def format_mentions(text, opts = {})
regex = /@\{([^;]+); ([^\}]+)\}/
form_message = text.to_str.gsub(regex) do |matched_string|
form_message = text.to_str.gsub(Mention::REGEX) do |matched_string|
people = self.mentioned_people
person = people.detect{ |p|
p.diaspora_handle == $~[2] unless p.nil?
......@@ -129,8 +128,7 @@ class StatusMessage < Post
end
def mentioned_people_from_string
regex = /@\{([^;]+); ([^\}]+)\}/
identifiers = self.raw_message.scan(regex).map do |match|
identifiers = self.raw_message.scan(Mention::REGEX).map do |match|
match.last
end
identifiers.empty? ? [] : Person.where(:diaspora_handle => identifiers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment