Class: Gdk::RGBA

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RGBA.



41
42
43
44
45
46
47
# File 'lib/gdk3/rgba.rb', line 41

def initialize(red=nil, green=nil, blue=nil, alpha=nil)
  initialize_raw
  self.red = red if red
  self.green = green if green
  self.blue = blue if blue
  self.alpha = alpha || 1.0
end

Class Method Details

.parse(spec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gdk3/rgba.rb', line 20

def parse(spec)
  rgba = new
  unless rgba.parse(spec)
    available_formats = [
      "COLOR_NAME",
      "\#RGB",
      "\#RRGGBB",
      "\#RRRGGGBBB",
      "\#RRRRGGGGBBBB",
      "rgb(R, G, B)",
      "rgba(R, G, B, A)",
    ]
    message = "invalid RGBA format: #{spec.inspect} "
    message << "(available formats: #{available_formats.join(', ')})"
    raise ArgumentError, message
  end
  rgba
end

Instance Method Details

#initialize_rawObject



40
# File 'lib/gdk3/rgba.rb', line 40

alias_method :initialize_raw, :initialize

#to_aObject



49
50
51
# File 'lib/gdk3/rgba.rb', line 49

def to_a
  [red, green, blue, alpha]
end