Sha256: 9d40cdd2bc169848c8e6bec6d635c4ca27b678c4b8e8102dec72727eafa9eb3f

Contents?: true

Size: 897 Bytes

Versions: 9

Compression:

Stored size: 897 Bytes

Contents

# encoding: utf-8

require 'equatable'

module Pastel
  # A class representing detached color
  class Detached
    include Equatable

    # Initialize a detached object
    #
    # @param [Pastel::Color] color
    #   the color instance
    # @param [Array[Symbol]] styles
    #   the styles to be applied
    #
    # @api private
    def initialize(color, *styles)
      @color  = color
      @styles = styles.dup
      freeze
    end

    # Decorate the values corresponding to styles
    #
    # @example
    #
    # @param [String] value
    #   the stirng to decorate with styles
    #
    # @return [String]
    #
    # @api public
    def call(*args)
      value = args.join
      @color.decorate(value, *styles)
    end
    alias_method :[], :call

    # @api public
    def to_proc
      self
    end

    private

    # @api private
    attr_reader :styles
  end # Detached
end # Pastel

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
pastel-0.7.4 lib/pastel/detached.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/detached.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/detached.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/detached.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/detached.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/pastel-0.7.3/lib/pastel/detached.rb
pastel-0.7.3 lib/pastel/detached.rb
pastel-0.7.2 lib/pastel/detached.rb
pastel-0.7.1 lib/pastel/detached.rb