Class: Rszr::Color::RGBA
- Inherits:
-
Object
- Object
- Rszr::Color::RGBA
- Defined in:
- lib/rszr/color.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
readonly
Returns the value of attribute alpha.
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Instance Method Summary collapse
-
#initialize(red, green, blue, alpha = 255) ⇒ RGBA
constructor
A new instance of RGBA.
- #to_hex(rgb: false) ⇒ Object
- #to_i(rgb: false) ⇒ Object
Constructor Details
#initialize(red, green, blue, alpha = 255) ⇒ RGBA
Returns a new instance of RGBA.
7 8 9 10 11 12 |
# File 'lib/rszr/color.rb', line 7 def initialize(red, green, blue, alpha = 255) if red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255 || alpha < 0 || alpha > 255 raise ArgumentError, 'color out of range' end @red, @green, @blue, @alpha = red, green, blue, alpha end |
Instance Attribute Details
#alpha ⇒ Object (readonly)
Returns the value of attribute alpha.
5 6 7 |
# File 'lib/rszr/color.rb', line 5 def alpha @alpha end |
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
5 6 7 |
# File 'lib/rszr/color.rb', line 5 def blue @blue end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
5 6 7 |
# File 'lib/rszr/color.rb', line 5 def green @green end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
5 6 7 |
# File 'lib/rszr/color.rb', line 5 def red @red end |
Instance Method Details
#to_hex(rgb: false) ⇒ Object
19 20 21 |
# File 'lib/rszr/color.rb', line 19 def to_hex(rgb: false) "%0#{rgb ? 6 : 8}x" % to_i(rgb: rgb) end |
#to_i(rgb: false) ⇒ Object
14 15 16 17 |
# File 'lib/rszr/color.rb', line 14 def to_i(rgb: false) i = red.to_i << 24 | green.to_i << 16 | blue.to_i << 8 | alpha.to_i rgb ? i >> 8 : i end |