Class: Decidim::ContentParsers::ProposalParser

Inherits:
ResourceParser show all
Defined in:
decidim-proposals/lib/decidim/content_parsers/proposal_parser.rb

Overview

A parser that searches mentions of Proposals in content.

This parser accepts two ways for linking Proposals.

  • Using a standard url starting with http or https.

  • With a word starting with ‘~` and digits afterwards will be considered a possible mentioned proposal.

For example ‘~1234`, but no `~ 1234`.

Also fills a ‘Metadata#linked_proposals` attribute.

Defined Under Namespace

Classes: Metadata

Constant Summary

Constants inherited from ResourceParser

ResourceParser::ID_REGEX, ResourceParser::URL_REGEX_CONTENT, ResourceParser::URL_REGEX_END_CHAR, ResourceParser::URL_REGEX_SCHEME

Constants inherited from BaseParser

BaseParser::Metadata

Instance Attribute Summary collapse

Attributes inherited from BaseParser

#content, #context

Instance Method Summary collapse

Methods inherited from ResourceParser

#rewrite

Methods inherited from BaseParser

#rewrite

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

#initialize(content, context) ⇒ ProposalParser

Returns a new instance of ProposalParser.



22
23
24
25
# File 'decidim-proposals/lib/decidim/content_parsers/proposal_parser.rb', line 22

def initialize(content, context)
  super
  @metadata = Metadata.new([])
end

Instance Attribute Details

#metadataMetadata (readonly)

This method is abstract.

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.

Examples:

Implementation for return a counter of prohibited words found

Metadata = Struct.new(:count)

def 
  Metadata.new(content.scan('foo').size)
end

Returns:

  • (Metadata)

    a Metadata object that holds extra information



28
29
30
# File 'decidim-proposals/lib/decidim/content_parsers/proposal_parser.rb', line 28

def 
  @metadata
end