Class: Decidim::DecidimAwesome::ContextAnalyzers::ComponentAnalyzer
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::ContextAnalyzers::ComponentAnalyzer
- Defined in:
- lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb
Overview
Translates a decidim component to detected participatory spaces and components
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #extract_context! ⇒ Object
-
#initialize(component) ⇒ ComponentAnalyzer
constructor
A new instance of ComponentAnalyzer.
Constructor Details
#initialize(component) ⇒ ComponentAnalyzer
Returns a new instance of ComponentAnalyzer.
8 9 10 11 |
# File 'lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb', line 8 def initialize(component) @component = component @context = {} end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
19 20 21 |
# File 'lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb', line 19 def component @component end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
19 20 21 |
# File 'lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb', line 19 def context @context end |
Class Method Details
.context_for(component) ⇒ Object
13 14 15 16 17 |
# File 'lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb', line 13 def self.context_for(component) analyzer = new component analyzer.extract_context! analyzer.context end |
Instance Method Details
#extract_context! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb', line 21 def extract_context! if @component.respond_to? :participatory_space @context[:participatory_space_manifest] = @component.participatory_space.manifest.name.to_s @context[:participatory_space_slug] = @component.participatory_space&.slug end if @component.respond_to? :component @context[:component_manifest] = @component.component.manifest.name.to_s @context[:component_id] = @component.component&.id&.to_s elsif @component.is_a? Decidim::Component @context[:component_manifest] = @component.manifest.name.to_s @context[:component_id] = @component&.id&.to_s end end |