class Color::Base
Attributes
components[RW]
Public Class Methods
average(colors)
click to toggle source
# File lib/quadtone/color.rb, line 29 def self.average(colors) avg_components = [] errors = [] component_names.each_with_index do |comp, i| avg_components << colors.map { |c| c.components[i] }.mean errors << colors.map { |c| c.components[i] }.standard_deviation end [new(avg_components), errors.max] end
cgats_fields()
click to toggle source
# File lib/quadtone/color.rb, line 13 def self.cgats_fields raise NotImplementedError, "\#cgats_fields not implemented in #{self}" end
colorspace_name()
click to toggle source
# File lib/quadtone/color.rb, line 21 def self.colorspace_name self.to_s.split('::').last.downcase end
component_names()
click to toggle source
# File lib/quadtone/color.rb, line 9 def self.component_names raise NotImplementedError, "\#component_names not implemented in #{self}" end
from_cgats(set)
click to toggle source
# File lib/quadtone/color.rb, line 25 def self.from_cgats(set) new(set.values_at(*cgats_fields)) end
new(arg)
click to toggle source
# File lib/quadtone/color.rb, line 39 def initialize(arg) components = case arg when String arg =~ /^(\w+)\((.+)\)$/ or raise "Can't initialize #{self.class}: bad color string: #{arg.inspect}" raise "Expected #{self.class.colorspace_name.inspect} but got #{$1.inspect}" if $1.downcase != self.class.colorspace_name $2.split(/,\s+/).map(&:to_f) when Hash self.class.component_names.map { |n| arg[n] } when Array arg.map(&:to_f) else raise "Can't initialize #{self.class}: unknown object: #{arg.inspect}" end raise "Can't initialize #{self.class}: too many components specified: #{components.inspect}" if components.length > self.class.num_components @components = [0] * self.class.num_components components.each_with_index { |n, i| @components[i] = n if n } end
num_components()
click to toggle source
# File lib/quadtone/color.rb, line 17 def self.num_components component_names.length end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/quadtone/color.rb, line 77 def <=>(other) @components <=> other.components end
eql?(other)
click to toggle source
# File lib/quadtone/color.rb, line 73 def eql?(other) @components == other.components end
hash()
click to toggle source
# File lib/quadtone/color.rb, line 69 def hash @components.hash end
to_cgats()
click to toggle source
# File lib/quadtone/color.rb, line 65 def to_cgats @components end
to_s()
click to toggle source
# File lib/quadtone/color.rb, line 57 def to_s "#{self.class.colorspace_name}(#{@components.map { |n| '%3.1f' % n }.join(', ')})" end
to_str()
click to toggle source
# File lib/quadtone/color.rb, line 61 def to_str to_s end