Sha256: 276baa7b63451b7bf1be80ca961f9e9cb86496abdd13a5b1400806c5ade7386e

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Satis
  module InfoItem
    class Component < Satis::ApplicationComponent
      attr_reader :options, :name, :icon, :group

      def initialize(name, *args, &block)
        super
        @name = name
        @args = args
        @options = args.extract_options!
        @group = options[:group]
        @icon = options[:icon]
        @placeholder = options[:placeholder] || '—'
      end

      def string_contents
        @content = options[:content]
        @content = @content.call if @content.respond_to?(:call)

        case @content.presence
        when Time
          @content.strftime('%Y-%m-%d %H:%M')
        when ActiveRecord::Base
          @content.try(:human_name) || @content.try(:name) || "#{@content.class} ##{@content.id}"
        when Symbol
          @content.to_s.humanize
        when ActiveSupport::SafeBuffer
          @content
        when String
          @content.humanize
        when nil
          @placeholder
        else
          @content
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
satis-1.0.75 app/components/satis/info_item/component.rb
satis-1.0.74 app/components/satis/info_item/component.rb
satis-1.0.70 app/components/satis/info_item/component.rb