Sha256: 4eb902919da1242441f1b0ddd813e4e3cc8ba1b72ec73f7488dffe9a22a66c22

Contents?: true

Size: 1.14 KB

Versions: 12

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Decidim
  #
  # Decorator for assembly members
  #
  class AssemblyMemberPresenter < SimpleDelegator
    def age
      (Time.current.strftime("%Y%m%d").to_i - birthday.strftime("%Y%m%d").to_i) / 10_000 if birthday
    end

    delegate :profile_url, :avatar_url, to: :user, allow_nil: true

    def name
      user ? user.name : full_name
    end

    def nickname
      user.nickname if user
    end

    def personal_information
      [
        gender.presence,
        age,
        birthplace.presence
      ].compact.join(" / ")
    end

    def position
      return position_other if __getobj__.position == "other"

      I18n.t(__getobj__.position, scope: "decidim.admin.models.assembly_member.positions", default: "")
    end

    def non_user_avatar_path
      return non_user_avatar.default_url unless non_user_avatar.attached?

      non_user_avatar.path
    end

    def non_user_avatar
      attached_uploader(:non_user_avatar)
    end

    private

    def user
      @user ||= begin
        if (user = __getobj__.user.presence)
          Decidim::UserPresenter.new(user)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-assemblies-0.26.10 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.9 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.8 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.7 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.5 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.4 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.3 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.2 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.1 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.0 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.0.rc2 app/presenters/decidim/assembly_member_presenter.rb
decidim-assemblies-0.26.0.rc1 app/presenters/decidim/assembly_member_presenter.rb