Class: Unmagic::Color::Chroma

Inherits:
Data
  • Object
show all
Includes:
Comparable
Defined in:
lib/unmagic/color.rb

Overview

OKLCH chroma unit (0-0.5)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:) ⇒ Chroma

Returns a new instance of Chroma.

Parameters:

  • value (Numeric)

    Chroma value (0-0.5)



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

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



256
257
258
# File 'lib/unmagic/color.rb', line 256

def value
  @value
end

Instance Method Details

#*(other) ⇒ Chroma

Returns New chroma.

Parameters:

  • other (Numeric)

    Multiplier

Returns:



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.

Parameters:

  • other (Numeric)

    Value to add

Returns:



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.

Parameters:

  • other (Numeric)

    Value to subtract

Returns:



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.

Parameters:

  • other (Numeric)

    Divisor

Returns:



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.

Parameters:

  • other (Chroma, Numeric)

    Value to compare

Returns:

  • (Integer, nil)

    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

#absChroma

Returns Absolute value.

Returns:



301
302
303
# File 'lib/unmagic/color.rb', line 301

def abs
  self.class.new(value: value.abs)
end

#to_fFloat

Returns Chroma value.

Returns:

  • (Float)

    Chroma value



265
# File 'lib/unmagic/color.rb', line 265

def to_f = value