Class: Hokusai::Color
- Inherits:
-
Object
- Object
- Hokusai::Color
- Defined in:
- ui/src/hokusai/types.rb
Overview
Color = Struct.new(:red, :green, :blue, :alpha) do
Instance Attribute Summary collapse
-
#alpha ⇒ Object
(also: #a)
readonly
Returns the value of attribute alpha.
-
#blue ⇒ Object
(also: #b)
readonly
Returns the value of attribute blue.
-
#green ⇒ Object
(also: #g)
readonly
Returns the value of attribute green.
-
#red ⇒ Object
(also: #r)
readonly
Returns the value of attribute red.
Class Method Summary collapse
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(red, green, blue, alpha = 255) ⇒ Color
constructor
A new instance of Color.
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
#alpha ⇒ Object (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 |
#blue ⇒ Object (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 |
#green ⇒ Object (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 |
#red ⇒ Object (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
#hash ⇒ Object
185 186 187 |
# File 'ui/src/hokusai/types.rb', line 185 def hash [self.class, r, g, b, a].hash end |