Class: Decidim::ContentParsers::UserParser
- Inherits:
-
BaseParser
- Object
- BaseParser
- Decidim::ContentParsers::UserParser
- Defined in:
- lib/decidim/content_parsers/user_parser.rb
Overview
A parser that searches user mentions in content.
A word starting with ‘@` will be considered as a possible mention if they only contains letters, numbers or underscores.
Defined Under Namespace
Classes: Metadata
Constant Summary collapse
- MENTION_REGEX =
Matches a nickname if contains letters, numbers or underscores.
/\B@(\w*)\b/
Constants inherited from BaseParser
Instance Attribute Summary
Attributes inherited from BaseParser
Instance Method Summary collapse
-
#metadata ⇒ Metadata
abstract
Collects and returns metadata.
-
#rewrite ⇒ String
Replaces found mentions matching a nickname of an existing user in the current organization with a global id.
Methods inherited from BaseParser
Constructor Details
This class inherits a constructor from Decidim::ContentParsers::BaseParser
Instance Method Details
#metadata ⇒ Metadata
Subclass is expected to implement it
Collects and returns metadata. This metadata is accessible at parsing time so it can be acted upon (sending emails to the users) or maybe even stored at the DB for later consultation.
34 35 36 |
# File 'lib/decidim/content_parsers/user_parser.rb', line 34 def Metadata.new(existing_users) end |
#rewrite ⇒ String
Replaces found mentions matching a nickname of an existing user in the current organization with a global id. Other mentions found that doesn’t match an existing user are returned as is.
27 28 29 30 31 |
# File 'lib/decidim/content_parsers/user_parser.rb', line 27 def rewrite content.gsub(MENTION_REGEX) do |match| users[match[1..-1].downcase]&.to_global_id&.to_s || match end end |