Class: Unmagic::Color::Hue

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

Overview

Angular unit for hue (0-360 degrees, wrapping)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:) ⇒ Hue

Returns a new instance of Hue.

Parameters:

  • value (Numeric)

    Hue value in degrees



206
207
208
# File 'lib/unmagic/color.rb', line 206

def initialize(value:)
  super(value: value.to_f % 360)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



202
203
204
# File 'lib/unmagic/color.rb', line 202

def value
  @value
end

Instance Method Details

#*(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Multiplier

Returns:

  • (Hue)

    New hue



227
228
229
# File 'lib/unmagic/color.rb', line 227

def *(other)
  self.class.new(value: value * other.to_f)
end

#+(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Value to add

Returns:

  • (Hue)

    New hue



239
240
241
# File 'lib/unmagic/color.rb', line 239

def +(other)
  self.class.new(value: value + other.to_f)
end

#-(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Value to subtract

Returns:

  • (Hue)

    New hue



245
246
247
# File 'lib/unmagic/color.rb', line 245

def -(other)
  self.class.new(value: value - other.to_f)
end

#/(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Divisor

Returns:

  • (Hue)

    New hue



233
234
235
# File 'lib/unmagic/color.rb', line 233

def /(other)
  self.class.new(value: value / other.to_f)
end

#<=>(other) ⇒ Integer?

Returns Comparison result.

Parameters:

  • other (Hue, Numeric)

    Value to compare

Returns:

  • (Integer, nil)

    Comparison result



218
219
220
221
222
223
# File 'lib/unmagic/color.rb', line 218

def <=>(other)
  case other
  when Hue, Numeric
    value <=> other.to_f
  end
end

#absHue

Returns Absolute value.

Returns:

  • (Hue)

    Absolute value



250
251
252
# File 'lib/unmagic/color.rb', line 250

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

#degreesFloat

Returns Hue value in degrees.

Returns:

  • (Float)

    Hue value in degrees



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

def degrees = value

#to_fFloat

Returns Hue value as float.

Returns:

  • (Float)

    Hue value as float



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

def to_f = value