Object
# File lib/term/ansicolor/attribute.rb, line 33 def self.[](name) case when self === name then name when Array === name then nearest_rgb_color name when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2" when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/ then nearest_rgb_color name when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/ then nearest_rgb_on_color name else get name end end
# File lib/term/ansicolor/attribute.rb, line 17 def self.attributes(&block) @__order__.map { |name| @__store__[name] } end
# File lib/term/ansicolor/attribute.rb, line 44 def self.get(name) @__store__[name.to_sym] end
# File lib/term/ansicolor/attribute.rb, line 52 def self.named_attributes(&block) @named_attributes ||= attributes.reject(&:rgb_color?).each(&block) end
# File lib/term/ansicolor/attribute.rb, line 56 def self.nearest_rgb_color(color, options = {}) rgb = RGBTriple[color] colors = rgb_colors if options.key?(:gray) && !options[:gray] colors = colors.reject(&:gray?) end colors.reject(&:background?).min_by { |c| c.distance_to(rgb, options) } end
# File lib/term/ansicolor/attribute.rb, line 65 def self.nearest_rgb_on_color(color, options = {}) rgb = RGBTriple[color] colors = rgb_colors if options.key?(:gray) && !options[:gray] colors = colors.reject(&:gray?) end colors.select(&:background?).min_by { |c| c.distance_to(rgb, options) } end
# File lib/term/ansicolor/attribute.rb, line 74 def initialize(name, code, options = {}) @name = name.to_sym @code = code.to_s if html = options[:html] @rgb = RGBTriple.from_html(html) elsif !options.empty? @rgb = RGBTriple.from_hash(options) else @rgb = nil # prevent instance variable not initialized warnings end end
# File lib/term/ansicolor/attribute.rb, line 96 def apply(string = nil, &block) ::Term::ANSIColor.color(self, string, &block) end
# File lib/term/ansicolor/attribute.rb, line 100 def background? @name.to_s.start_with?('on_') end
# File lib/term/ansicolor/attribute.rb, line 88 def code if rgb_color? background? ? "48;5;#{@code}" : "38;5;#{@code}" else @code end end
# File lib/term/ansicolor/attribute.rb, line 118 def distance_to(other, options = {}) if our_rgb = to_rgb_triple and other.respond_to?(:to_rgb_triple) and other_rgb = other.to_rgb_triple then our_rgb.distance_to(other_rgb, options) else 1 / 0.0 end end
# File lib/term/ansicolor/attribute.rb, line 129 def gradient_to(other, options = {}) if our_rgb = to_rgb_triple and other.respond_to?(:to_rgb_triple) and other_rgb = other.to_rgb_triple then our_rgb.gradient_to(other_rgb, options).map do |rgb_triple| self.class.nearest_rgb_color(rgb_triple, options) end else [] end end
# File lib/term/ansicolor/attribute.rb, line 110 def gray? rgb_color? && to_rgb_triple.gray? end
Generated with the Darkfish Rdoc Generator 2.