Class: Unmagic::Color::Hue
- Inherits:
-
Data
- Object
- Data
- Unmagic::Color::Hue
- Includes:
- Comparable
- Defined in:
- lib/unmagic/color.rb
Overview
Angular unit for hue (0-360 degrees, wrapping)
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#*(other) ⇒ Hue
New hue.
-
#+(other) ⇒ Hue
New hue.
-
#-(other) ⇒ Hue
New hue.
-
#/(other) ⇒ Hue
New hue.
-
#<=>(other) ⇒ Integer?
Comparison result.
-
#abs ⇒ Hue
Absolute value.
-
#degrees ⇒ Float
Hue value in degrees.
-
#initialize(value:) ⇒ Hue
constructor
A new instance of Hue.
-
#to_f ⇒ Float
Hue value as float.
Constructor Details
#initialize(value:) ⇒ Hue
Returns a new instance of Hue.
206 207 208 |
# File 'lib/unmagic/color.rb', line 206 def initialize(value:) super(value: value.to_f % 360) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value
202 203 204 |
# File 'lib/unmagic/color.rb', line 202 def value @value end |
Instance Method Details
#*(other) ⇒ Hue
Returns 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.
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.
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.
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.
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 |
#abs ⇒ Hue
Returns Absolute value.
250 251 252 |
# File 'lib/unmagic/color.rb', line 250 def abs self.class.new(value: value.abs) end |
#degrees ⇒ Float
Returns Hue value in degrees.
214 |
# File 'lib/unmagic/color.rb', line 214 def degrees = value |
#to_f ⇒ Float
Returns Hue value as float.
211 |
# File 'lib/unmagic/color.rb', line 211 def to_f = value |