Class: Color
- Inherits:
-
Object
- Object
- Color
- Defined in:
- lib/colver/color.rb
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#hex ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute hex.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Instance Method Summary collapse
-
#initialize(color) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
-
#invert ⇒ Object
Inverts a color.
- #rgb ⇒ Object (also: #to_a)
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
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
5 6 7 |
# File 'lib/colver/color.rb', line 5 def blue @blue end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
5 6 7 |
# File 'lib/colver/color.rb', line 5 def green @green end |
#hex ⇒ Object (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 |
#red ⇒ Object (readonly)
Returns the value of attribute red.
5 6 7 |
# File 'lib/colver/color.rb', line 5 def red @red end |
Instance Method Details
#inspect ⇒ Object
23 24 25 |
# File 'lib/colver/color.rb', line 23 def inspect "#<Color: hex: #{hex}, rgb: #{rgb}>" end |
#invert ⇒ Object
Inverts a color
28 29 30 |
# File 'lib/colver/color.rb', line 28 def invert Color.new rgb.map{|value| 255 - value} end |
#rgb ⇒ Object Also known as: to_a
18 19 20 |
# File 'lib/colver/color.rb', line 18 def rgb [@red, @green, @blue] end |