123456789_123456789_123456789_123456789_123456789_

Class: Minitest::PrideLOL

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrideIO
Instance Chain:
self, PrideIO
Inherits: Minitest::PrideIO
Defined in: lib/minitest/pride_plugin.rb

Overview

If you thought the PrideIO was colorful…

(Inspired by lolcat, but with clean math)

Constant Summary

PrideIO - Inherited

ESC, NND

Class Attribute Summary

PrideIO - Inherited

.pride?

Are we showing our testing pride?

Class Method Summary

PrideIO - Inherited

.pride!

Activate the pride plugin.

.new

Instance Attribute Summary

PrideIO - Inherited

#io

The IO we’re going to pipe through.

Instance Method Summary

PrideIO - Inherited

#pride

Color a string.

#print

Wrap print to colorize the output.

#method_missing, #puts

Constructor Details

.new(io) ⇒ PrideLOL

This method is for internal use only.
[ GitHub ]

  
# File 'lib/minitest/pride_plugin.rb', line 109

def initialize io # :nodoc:
  # walk red, green, and blue around a circle separated by equal thirds.
  #
  # To visualize, type this into wolfram-alpha:
  #
  #   plot (3*sin(x)+3), (3*sin(x2*pi/3)3), (3*sin(x4*pi/3)3)

  @colors = (6 * 7).times.map { |n|
    n *= 1.0 / 3
    r  = (3 * Math.sin(n           ) + 3).to_i
    g  = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
    b  = (3 * Math.sin(n + 2 * PI_3) + 3).to_i

    # Then we take rgb and encode them in a single number using
    # base 6, shifted by 16 for the base 16 ansi colors.
    36 * r + 6 * g + b + 16
  }.rotate(4) # puts "red" first

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Minitest::PrideIO

Instance Method Details

#pride(string)

Make the string even more colorful. Damnit.

[ GitHub ]

  
# File 'lib/minitest/pride_plugin.rb', line 133

def pride string
  c = @colors[@index % @size]
  @index += 1
  "#{ESC}38;5;#{c}m#{string}#{NND}"
end