Sha256: e0b8f250e3aae4c3ce833007c3cf5bad3ac6fd389305e8563e35890991423d98

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

module Troo
  module Presenters
    class List
      include DecoratorHelpers

      # @param  [Troo::List]
      # @return [Troo::Presenters::List]
      def initialize(list, options = {})
        @list, @options = list, options
      end

      # @return [String]
      def show
        output.render Presenters::Resource.list_view(list.board)

        output.spacer

        output.indent do
          render_list
        end
      end

      # @return [String]
      def render_list
        output.render Presenters::Resource.list_view(list)

        output.indent do
          if list.cards.empty?
            output.spacer do
              output.render error('No cards were found.')
            end
          else
            render_cards
          end
        end
      end

      # @return [String]
      def render_cards
        output.spacer do
          list.cards.map do |card|
            output.render Presenters::Resource.list_view(card)
          end
        end
      end

      private

      attr_reader :list

      def output
        @output ||= options.fetch(:output)
      end

      def options
        defaults.merge!(@options)
      end

      def defaults
        {
          output: Troo::Output.new
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
troo-0.0.15 lib/troo/presenters/list.rb
troo-0.0.14 lib/troo/presenters/list.rb
troo-0.0.13 lib/troo/presenters/list.rb
troo-0.0.12 lib/troo/presenters/list.rb
troo-0.0.11 lib/troo/presenters/list.rb