Class: Decidim::Accountability::ResultSerializer

Inherits:
Exporters::Serializer show all
Includes:
ResourceHelper, TranslationsHelper
Defined in:
decidim-accountability/lib/decidim/accountability/result_serializer.rb

Overview

This class serializes a Result so can be exported to CSV, JSON or other formats.

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #resource_locator, #resource_title

Methods inherited from Exporters::Serializer

#event_name, #finalize, #run

Constructor Details

#initialize(result) ⇒ ResultSerializer

Public: Initializes the serializer with a result.



12
13
14
# File 'decidim-accountability/lib/decidim/accountability/result_serializer.rb', line 12

def initialize(result)
  @result = result
end

Instance Method Details

#serializeObject

Public: Exports a hash with the serialized data for this result.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'decidim-accountability/lib/decidim/accountability/result_serializer.rb', line 17

def serialize
  {
    id: result.id,
    category: {
      id: result.category.try(:id),
      name: result.category.try(:name) || empty_translatable
    },
    scope: {
      id: result.scope.try(:id),
      name: result.scope.try(:name) || empty_translatable
    },
    parent: {
      id: result.parent.try(:id)
    },
    title: result.title,
    description: result.description,
    start_date: result.start_date,
    end_date: result.end_date,
    status: {
      id: result.status.try(:id),
      key: result.status.try(:key),
      name: result.status.try(:name) || empty_translatable
    },
    progress: result.progress,
    created_at: result.created_at,
    url:,
    component: { id: component.id },
    proposal_urls: proposals
  }
end