Class: Unmagic::Color::Chroma
- Inherits:
-
Data
- Object
- Data
- Unmagic::Color::Chroma
- Includes:
- Comparable
- Defined in:
- lib/unmagic/color.rb
Overview
OKLCH chroma unit (0-0.5)
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#*(other) ⇒ Chroma
New chroma.
-
#+(other) ⇒ Chroma
New chroma.
-
#-(other) ⇒ Chroma
New chroma.
-
#/(other) ⇒ Chroma
New chroma.
-
#<=>(other) ⇒ Integer?
Comparison result.
-
#abs ⇒ Chroma
Absolute value.
-
#initialize(value:) ⇒ Chroma
constructor
A new instance of Chroma.
-
#to_f ⇒ Float
Chroma value.
Constructor Details
#initialize(value:) ⇒ Chroma
Returns a new instance of Chroma.
260 261 262 |
# File 'lib/unmagic/color.rb', line 260 def initialize(value:) super(value: value.to_f.clamp(0, 0.5)) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value
256 257 258 |
# File 'lib/unmagic/color.rb', line 256 def value @value end |
Instance Method Details
#*(other) ⇒ Chroma
Returns New chroma.
278 279 280 |
# File 'lib/unmagic/color.rb', line 278 def *(other) self.class.new(value: value * other.to_f) end |
#+(other) ⇒ Chroma
Returns New chroma.
290 291 292 |
# File 'lib/unmagic/color.rb', line 290 def +(other) self.class.new(value: value + other.to_f) end |
#-(other) ⇒ Chroma
Returns New chroma.
296 297 298 |
# File 'lib/unmagic/color.rb', line 296 def -(other) self.class.new(value: value - other.to_f) end |
#/(other) ⇒ Chroma
Returns New chroma.
284 285 286 |
# File 'lib/unmagic/color.rb', line 284 def /(other) self.class.new(value: value / other.to_f) end |
#<=>(other) ⇒ Integer?
Returns Comparison result.
269 270 271 272 273 274 |
# File 'lib/unmagic/color.rb', line 269 def <=>(other) case other when Chroma, Numeric value <=> other.to_f end end |
#abs ⇒ Chroma
Returns Absolute value.
301 302 303 |
# File 'lib/unmagic/color.rb', line 301 def abs self.class.new(value: value.abs) end |
#to_f ⇒ Float
Returns Chroma value.
265 |
# File 'lib/unmagic/color.rb', line 265 def to_f = value |