Sha256: 424a248a854d2484de41f27e107ed0db6932be1e954f6b324d72963bf481f7ff

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

require_relative 'safe/format'

class String
  alias :old_method_missing :method_missing
  alias :old_respond_to? :respond_to?

  def method_missing(method, *args)
    name   = method.to_s
    colors = 'black|red|green|yellow|blue|purple|cyan|white|none'
    if (name =~ /format(_bold)?(_underline)?(?:_fg_(#{colors}))?(?:_bg_(#{colors}))?/).nil?
      old_method_missing(method, *args)
    else
      EverydayCliUtils::Format::format(self, EverydayCliUtils::Format::build_string(!$1.nil?, !$2.nil?, $3.nil? ? nil : $3.to_sym, $4.nil? ? nil : $4.to_sym))
    end
  end

  def respond_to?(method)
    name   = method.to_s
    colors = 'black|red|green|yellow|blue|purple|cyan|white|none'
    (!(name =~ /format(_bold)?(_underline)?(?:_fg_(#{colors}))?(?:_bg_(#{colors}))?/).nil?) || old_respond_to?(method)
  end

  def format_all
    EverydayCliUtils::Format::format_all(self)
  end

  def remove_format
    EverydayCliUtils::Format::remove_format(self)
  end

  def mycenter(len, char = ' ')
    EverydayCliUtils::Format::mycenter(self, len, char)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
everyday-cli-utils-1.8.5 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.8.4 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.8.3 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.8.2 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.8.1 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.8.0 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.7.4 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.7.3 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.7.2 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.7.1 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.7.0 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.6.0 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.5.2 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.5.1 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.5.0 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.4.0 lib/everyday-cli-utils/format.rb
everyday-cli-utils-1.3.0 lib/everyday-cli-utils/format.rb