Sha256: 33027a7906f2abf5ba209254e03be79e07e3f8222ff96873c54f79a14d30566b

Contents?: true

Size: 811 Bytes

Versions: 3

Compression:

Stored size: 811 Bytes

Contents

module Troo
  class ListDecorator
    include DecoratorHelpers

    def initialize(list, options = {})
      @list = list
      @options = options
    end

    def short
      [default_str, id_str, name_str].join + "\n"
    end

    def name_str
      highlight(name, options)
    end

    def default_str
      default.center(3)
    end

    def id_str
      highlight(brackets(id) + " ", options).rjust(6)
    end

    def name
      (list.name && list.name.chomp) || "N/A"
    end

    def default
      list.default? ? "*" : ""
    end

    def id
      list.id.to_s
    end

    private
    attr_reader :list

    def options
      defaults.merge!(@options)
    end

    def defaults
      {
        ansicolor: true,
        colour:    Esc.green,
        underline: Esc.underline
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troo-0.0.4 lib/troo/display/list_decorator.rb
troo-0.0.3 lib/troo/display/list_decorator.rb
troo-0.0.2 lib/troo/display/list_decorator.rb