Class: Color

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Color

Returns a new instance of Color.



8
9
10
11
12
13
14
15
16
# File 'lib/colver/color.rb', line 8

def initialize(color)
  if color.class == Array
    from_array color
  elsif color.class == String
    from_string color
  else
    raise ArgumentError, "Color#new argument must be an array or a string!"
  end
end

Instance Attribute Details

#blueObject (readonly)

Returns the value of attribute blue.



5
6
7
# File 'lib/colver/color.rb', line 5

def blue
  @blue
end

#greenObject (readonly)

Returns the value of attribute green.



5
6
7
# File 'lib/colver/color.rb', line 5

def green
  @green
end

#hexObject (readonly) Also known as: to_s

Returns the value of attribute hex.



5
6
7
# File 'lib/colver/color.rb', line 5

def hex
  @hex
end

#redObject (readonly)

Returns the value of attribute red.



5
6
7
# File 'lib/colver/color.rb', line 5

def red
  @red
end

Instance Method Details

#inspectObject



23
24
25
# File 'lib/colver/color.rb', line 23

def inspect
  "#<Color: hex: #{hex}, rgb: #{rgb}>"
end

#invertObject

Inverts a color



28
29
30
# File 'lib/colver/color.rb', line 28

def invert
  Color.new rgb.map{|value| 255 - value}
end

#rgbObject Also known as: to_a



18
19
20
# File 'lib/colver/color.rb', line 18

def rgb
  [@red, @green, @blue]
end