Sha256: 9853326e0901221653748756fc87ddab5dca124b2c87351dfdbb303f8a6020cb

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

module Tr3llo
  module Presenter
    module Card
      class ListPresenter
        def initialize(interface)
          @interface = interface
        end

        def print!(list, cards)
          interface.print_frame do
            interface.puts("##{list[:name]}".purple)
            interface.puts("=" * list[:name].length)
            cards.each { |card| present_card(card) }
          end
        end

        private

        attr_reader :interface

        def present_card(card)
          if card.has_key?(:labels)
            label_str = card[:labels].map { |label| colorize_label(label) }.join(", ")
          else
            label_str = ''
          end

          if card.has_key?(:members)
            members_str = card[:members].map { |member| "@#{member[:username]}".blue }.join(", ")
          else
            members_str = ''
          end

          if card[:subscribed]
            subscribed_str = "[✓]"
          else
            subscribed_str = "[ ]"
          end

          interface.puts "[#{subscribed_str} #{card[:id].labelize}] - #{card[:name]} (#{label_str}) [#{members_str}]"
        end

        def colorize_label(label)
          if label[:color]
            "##{label[:name]}".paint(label[:color])
          else
            "##{label[:name]}"
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
3llo-0.3.1 lib/3llo/presenter/card/list.rb
3llo-0.3.0 lib/3llo/presenter/card/list.rb
3llo-0.2.0 lib/3llo/presenter/card/list.rb
3llo-0.1.12 lib/3llo/presenter/card/list.rb