Sha256: 3694176d6c6d2a1a26cff6458e6b7b2ef1b123957a8ca0d8be0187dda508806e

Contents?: true

Size: 718 Bytes

Versions: 64

Compression:

Stored size: 718 Bytes

Contents

# frozen_string_literal: true

module Decidim
  #
  # Presenter for metric objects
  #
  class MetricObjectPresenter < SimpleDelegator
    def attr_int(attr, default: 0)
      return default unless __getobj__

      __getobj__[attr] || default
    end

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

      __getobj__[attr].presence || default
    end

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

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

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

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

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.4 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.27.9 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.29.0 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.3 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.27.8 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.29.0.rc4 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.29.0.rc3 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.29.0.rc2 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.29.0.rc1 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.2 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.27.7 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.1 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.27.6 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.26.10 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.26.9 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.0 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.27.5 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.0.rc5 app/presenters/decidim/metric_object_presenter.rb
decidim-core-0.28.0.rc4 app/presenters/decidim/metric_object_presenter.rb