Sha256: ff6d2bc9768eb8b2e71b7e0560e98d15f460f22980ac0e58642a659f558c0f68
Contents?: true
Size: 809 Bytes
Versions: 6
Compression:
Stored size: 809 Bytes
Contents
# frozen_string_literal: true module DevSuite module Utils module Color module Strategy class Theme < Base def initialize(palette) super() @palette = palette end def colorize(text, color: :default) unless @palette.colors.key?(color) raise ArgumentError, "Invalid color key" end color_code = @palette.colors[color] unless valid_color_code?(color_code) raise ArgumentError, "Invalid color code" end "\e[#{color_code}m#{text}\e[0m" end private def valid_color_code?(color_code) color_code.is_a?(Integer) && color_code.between?(0, 255) end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems