move mention regex to a constant in mention
This commit is contained in:
parent
718c4fd38c
commit
117acdd17f
2 changed files with 4 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue