Sha256: a8280614fd11cf2205270274c5f91ab7c0adc38488a8e24ecb25c61310f2b1a9

Contents?: true

Size: 1.68 KB

Versions: 24

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require 'time'
require 'active_support/core_ext/numeric/time'
require_relative '../../models/entry_group'
require_relative '../../support/color_themable'
require_relative '../../support/time_formatable'

module Dsu
  module Views
    module EntryGroup
      class Show
        include Support::ColorThemable
        include Support::TimeFormatable

        def initialize(entry_group:, options: {})
          raise ArgumentError, 'entry_group is nil' if entry_group.nil?
          raise ArgumentError, 'entry_group is the wrong object type' unless entry_group.is_a?(Models::EntryGroup)
          raise ArgumentError, 'options is nil' if options.nil?
          raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

          @entry_group = entry_group
          @options = options || {}
        end

        def call
          render!
        end
        alias render call

        private

        attr_reader :entry_group, :options

        def render!
          puts presenter.formatted_time

          entry_group.validate!
          puts presenter.no_entries_available and return if entry_group.entries.empty?

          entry_group.entries.each_with_index do |entry, index|
            entry_presenter = entry.presenter
            puts entry_presenter.formatted_description_with_index(index: index)
          end
        rescue ActiveModel::ValidationError
          puts apply_theme(errors(entry_group), theme_color: presenter.color_theme.error)
        end

        def errors(model)
          model.errors.full_messages.join(', ')
        end

        def presenter
          @presenter ||= entry_group.presenter
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dsu-2.0.3 lib/dsu/views/entry_group/show.rb
dsu-2.0.2 lib/dsu/views/entry_group/show.rb
dsu-2.0.1 lib/dsu/views/entry_group/show.rb
dsu-2.0.0.alpha.1 lib/dsu/views/entry_group/show.rb