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.
232 233 234 |
# File 'lib/unmagic/color.rb', line 232 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
228 229 230 |
# File 'lib/unmagic/color.rb', line 228 def value @value end |
Instance Method Details
#*(other) ⇒ Chroma
Returns New chroma.
250 251 252 |
# File 'lib/unmagic/color.rb', line 250 def *(other) self.class.new(value: value * other.to_f) end |
#+(other) ⇒ Chroma
Returns New chroma.
262 263 264 |
# File 'lib/unmagic/color.rb', line 262 def +(other) self.class.new(value: value + other.to_f) end |
#-(other) ⇒ Chroma
Returns New chroma.
268 269 270 |
# File 'lib/unmagic/color.rb', line 268 def -(other) self.class.new(value: value - other.to_f) end |
#/(other) ⇒ Chroma
Returns New chroma.
256 257 258 |
# File 'lib/unmagic/color.rb', line 256 def /(other) self.class.new(value: value / other.to_f) end |
#<=>(other) ⇒ Integer?
Returns Comparison result.
241 242 243 244 245 246 |
# File 'lib/unmagic/color.rb', line 241 def <=>(other) case other when Chroma, Numeric value <=> other.to_f end end |
#abs ⇒ Chroma
Returns Absolute value.
273 274 275 |
# File 'lib/unmagic/color.rb', line 273 def abs self.class.new(value: value.abs) end |
#to_f ⇒ Float
Returns Chroma value.
237 |
# File 'lib/unmagic/color.rb', line 237 def to_f = value |