Class: Decidim::DecidimAwesome::ContextAnalyzers::ComponentAnalyzer

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#componentObject (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

#contextObject (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