Class: Sassafras::ColorSet

Inherits:
Object
  • Object
show all
Defined in:
lib/sassafras.rb

Direct Known Subclasses

Shades, Tints

Instance Method Summary collapse

Constructor Details

#initialize(base_rgb, prefix = nil) ⇒ ColorSet

Returns a new instance of ColorSet.



129
130
131
132
133
# File 'lib/sassafras.rb', line 129

def initialize(base_rgb, prefix=nil)
  @rgb = base_rgb
  @prefix = prefix
  @colors = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



147
148
149
150
# File 'lib/sassafras.rb', line 147

def method_missing(method, *args)
  return @colors[method.to_s] if @colors[method.to_s]
  super
end

Instance Method Details

#colorsObject



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/sassafras.rb', line 135

def colors
  returning Hash.new do |hash|
    @colors.each do |name, hex|
      if @prefix
        hash["#{@prefix}_#{name}"] = hex
      else
        hash[name] = hex
      end
    end
  end
end