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



181
182
183
# File 'lib/unmagic/color.rb', line 181

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



177
178
179
# File 'lib/unmagic/color.rb', line 177

def value
  @value
end

Instance Method Details

#*(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Multiplier

Returns:

  • (Hue)

    New hue



199
200
201
# File 'lib/unmagic/color.rb', line 199

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



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

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



217
218
219
# File 'lib/unmagic/color.rb', line 217

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

#/(other) ⇒ Hue

Returns New hue.

Parameters:

  • other (Numeric)

    Divisor

Returns:

  • (Hue)

    New hue



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

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



190
191
192
193
194
195
# File 'lib/unmagic/color.rb', line 190

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

#absHue

Returns Absolute value.

Returns:

  • (Hue)

    Absolute value



222
223
224
# File 'lib/unmagic/color.rb', line 222

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

#degreesObject



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

def degrees = value

#to_fObject



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

def to_f = value