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
17
# File 'lib/colver/color.rb', line 8

def initialize(color)
  case color
  when Array
    from_array color
  when 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

#eql?(other_color) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


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

def eql?(other_color)
  self.class.equal?(other_color.class) && hex == other_color.hex
end

#inspectObject



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

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

#invertObject

Inverts a color



34
35
36
# File 'lib/colver/color.rb', line 34

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

#rgbObject Also known as: to_a



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

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