Sha256: 754850dee2c998ef1923c96e83bd5a4026b3cfe56b7d85c8809d10e7f9e21374

Contents?: true

Size: 938 Bytes

Versions: 172

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/enum'
require 'eac_ruby_utils/core_ext'

module EacCli
  # A [EacRubyUtils::Enum] which each value is associated with one console color.
  class Enum < ::EacRubyUtils::Enum
    # Foreground color used in [to_bg_label]
    TO_BG_LABEL_FG_COLOR = :light_white

    attr_reader :color

    def initialize(key, color)
      super(key)
      @color = color
    end

    delegate :to_s, to: :key

    # @return [String]
    def to_label
      to_fg_label
    end

    # @return [String]
    def to_fg_label
      to_fg_bg_label(color)
    end

    # @return [String]
    def to_bg_label
      to_fg_bg_label(TO_BG_LABEL_FG_COLOR, color)
    end

    private

    # @return [String]
    def to_fg_bg_label(fg_color, bg_color = nil)
      colors = { color: fg_color }
      bg_color.if_present { |v| colors[:background] = v }
      ::ColorizedString[to_s].colorize(colors)
    end
  end
end

Version data entries

172 entries across 172 versions & 3 rubygems

Version Path
eac_cli-0.42.0 lib/eac_cli/enum.rb
eac_cli-0.40.1 lib/eac_cli/enum.rb
eac_cli-0.40.0 lib/eac_cli/enum.rb
eac_cli-0.39.0 lib/eac_cli/enum.rb
eac_cli-0.38.1 lib/eac_cli/enum.rb
eac_tools-0.82.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.81.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_cli-0.38.0 lib/eac_cli/enum.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.76.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.75.2 sub/eac_cli/lib/eac_cli/enum.rb
eac_cli-0.37.0 lib/eac_cli/enum.rb
eac_tools-0.75.1 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.75.0 sub/eac_cli/lib/eac_cli/enum.rb
eac_tools-0.74.1 sub/eac_cli/lib/eac_cli/enum.rb