Module: Palettes::Mixin

Included in:
ColourLovers
Defined in:
lib/mixin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



7
8
9
# File 'lib/mixin.rb', line 7

def colors
  @colors
end

Instance Method Details

#[](arg) ⇒ Object



31
32
33
34
# File 'lib/mixin.rb', line 31

def [](arg)
  color = arg.is_a?(Integer) ? @palette[arg] : @palette.assoc(arg)
  color.respond_to?(:last) ? color.last : color
end

#fill(color_array) ⇒ Object

Palette colors may be supplied as an array of values, or an array of name/value pairs: Palette.new [ “#eeeeee”, “#666600” ] Palette.new [ [“red”, “#ff0000”], [“blue”, “#0000ff”] ]



13
14
15
# File 'lib/mixin.rb', line 13

def fill(color_array)
  @palette = color_array
end

#namesObject



24
25
26
27
28
29
# File 'lib/mixin.rb', line 24

def names
  n = []
  # We could use #map here, but then I'd have to use #compact
  @palette.each { |c| c.respond_to?( :assoc ) ? n << c.first : nil }
  n.empty? ? nil : n
end

#rawObject



40
41
42
# File 'lib/mixin.rb', line 40

def raw
  @palette
end

#to_hashObject



36
37
38
# File 'lib/mixin.rb', line 36

def to_hash
  Hash[ *@palette.flatten ]
end