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
- #eql?(other_color) ⇒ Boolean (also: #==)
-
#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 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
#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
#eql?(other_color) ⇒ Boolean Also known as: ==
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 |
#inspect ⇒ Object
29 30 31 |
# File 'lib/colver/color.rb', line 29 def inspect "#<Color: hex: #{hex}, rgb: #{rgb}>" end |
#invert ⇒ Object
Inverts a color
34 35 36 |
# File 'lib/colver/color.rb', line 34 def invert Color.new rgb.map{|value| 255 - value} end |
#rgb ⇒ Object Also known as: to_a
19 20 21 |
# File 'lib/colver/color.rb', line 19 def rgb [@red, @green, @blue] end |