Sha256: 8953ac7f4acba26c57f00b95b02425b37d6f2008e3e9c901be50f75548e4587b

Contents?: true

Size: 640 Bytes

Versions: 98

Compression:

Stored size: 640 Bytes

Contents

require 'ansi/code'

module ANSI

  # ANSI::Chain was inspired by Kazuyoshi Tlacaelel's Isna library.
  #
  class Chain

    #
    def initialize(string)
      @string = string.to_s
      @codes  = []
    end

    #
    attr :string

    #
    attr :codes

    #
    def method_missing(s, *a, &b)
      if ANSI::CHART.key?(s)
        @codes << s
        self
      else
        super(s, *a, &b)
      end
    end

    #
    def to_s
      if codes.empty?
        result = @string
      else
        result = Code.ansi(@string, *codes)
        codes.clear
      end
      result
    end

    #
    def to_str
      to_s
    end

  end

end

Version data entries

98 entries across 56 versions & 17 rubygems

Version Path
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/bundle/ruby/2.7.0/gems/paynow_sdk-1.0.9/vendor/bundle/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.1.0 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.9 vendor/bundle/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.9 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.8 vendor/bundle/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.8 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.7 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.6 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.6 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.5 vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb
paynow_sdk-1.0.5 vendor/cache/ruby/2.7.0/gems/paynow_sdk-1.0.0/vendor/cache/ruby/2.7.0/gems/ansi-1.5.0/lib/ansi/chain.rb