Class: Decidim::MetricObjectPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
decidim-core/app/presenters/decidim/metric_object_presenter.rb

Overview

Presenter for metric objects

Instance Method Summary collapse

Instance Method Details

#attr_date(attr, default: "") ⇒ Object


20
21
22
23
24
# File 'decidim-core/app/presenters/decidim/metric_object_presenter.rb', line 20

def attr_date(attr, default: "")
  return default unless __getobj__

  __getobj__[attr].try(:strftime, "%Y-%m-%d") || default
end

#attr_int(attr, default: 0) ⇒ Object


8
9
10
11
12
# File 'decidim-core/app/presenters/decidim/metric_object_presenter.rb', line 8

def attr_int(attr, default: 0)
  return default unless __getobj__

  __getobj__[attr] || default
end

#attr_string(attr, default: "") ⇒ Object


14
15
16
17
18
# File 'decidim-core/app/presenters/decidim/metric_object_presenter.rb', line 14

def attr_string(attr, default: "")
  return default unless __getobj__

  __getobj__[attr].presence || default
end

#attr_translated(attr, locale: I18n.locale, default: "") ⇒ Object


26
27
28
29
30
# File 'decidim-core/app/presenters/decidim/metric_object_presenter.rb', line 26

def attr_translated(attr, locale: I18n.locale, default: "")
  return default unless __getobj__

  __getobj__[attr].try(:[], locale.to_s).presence || default
end