Class: Hokusai::Color

Inherits:
Object
  • Object
show all
Defined in:
ui/src/hokusai/types.rb

Overview

Color = Struct.new(:red, :green, :blue, :alpha) do

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(red, green, blue, alpha = 255) ⇒ Color

Returns a new instance of Color.



159
160
161
162
163
164
# File 'ui/src/hokusai/types.rb', line 159

def initialize(red, green, blue, alpha = 255)
  @red = red.freeze
  @green = green.freeze
  @blue = blue.freeze
  @alpha = alpha.freeze
end

Instance Attribute Details

#alphaObject (readonly) Also known as: a

Returns the value of attribute alpha.



158
159
160
# File 'ui/src/hokusai/types.rb', line 158

def alpha
  @alpha
end

#blueObject (readonly) Also known as: b

Returns the value of attribute blue.



158
159
160
# File 'ui/src/hokusai/types.rb', line 158

def blue
  @blue
end

#greenObject (readonly) Also known as: g

Returns the value of attribute green.



158
159
160
# File 'ui/src/hokusai/types.rb', line 158

def green
  @green
end

#redObject (readonly) Also known as: r

Returns the value of attribute red.



158
159
160
# File 'ui/src/hokusai/types.rb', line 158

def red
  @red
end

Class Method Details

.convert(value) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'ui/src/hokusai/types.rb', line 171

def self.convert(value)
  case value
  when String
    value = value.split(",").map(&:to_i)
  when Array
  when Color
    return value
  else
    raise Hokusai::Error.new("Unsupported conversion type #{value.class} for Hokusai::Color")
  end

  new(value[0], value[1], value[2], value[3] || 255)
end

Instance Method Details

#hashObject



185
186
187
# File 'ui/src/hokusai/types.rb', line 185

def hash
  [self.class, r, g, b, a].hash
end