Class: Ferrum::RGBA

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/rgba.rb

Overview

Represents an RGBA color, validating that the red/green/blue components are integers between 0 and 255 and that alpha is a float between 0.0 and 1.0. Used e.g. as the background color option for screenshots.

Instance Method Summary collapse

Constructor Details

#initialize(red, green, blue, alpha) ⇒ RGBA

Returns a new instance of RGBA.



10
11
12
13
14
15
16
17
# File 'lib/ferrum/rgba.rb', line 10

def initialize(red, green, blue, alpha)
  self.red = red
  self.green = green
  self.blue = blue
  self.alpha = alpha

  validate
end

Instance Method Details

#to_hHash{Symbol => Integer, Float}

Converts the color to a Hash.

Returns:

  • (Hash{Symbol => Integer, Float})


24
25
26
# File 'lib/ferrum/rgba.rb', line 24

def to_h
  { r: red, g: green, b: blue, a: alpha }
end