Class: Unmagic::Color::Component
- Inherits:
-
Data
- Object
- Data
- Unmagic::Color::Component
- Includes:
- Comparable
- Defined in:
- lib/unmagic/color.rb
Overview
Base unit for RGB components (0-255)
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#*(other) ⇒ Component
New component.
-
#+(other) ⇒ Component
New component.
-
#-(other) ⇒ Component
New component.
-
#/(other) ⇒ Component
New component.
-
#<=>(other) ⇒ Integer?
Comparison result.
-
#abs ⇒ Component
Absolute value.
-
#initialize(value:) ⇒ Component
constructor
A new instance of Component.
- #to_f ⇒ Object
- #to_i ⇒ Object
Constructor Details
#initialize(value:) ⇒ Component
Returns a new instance of Component.
123 124 125 |
# File 'lib/unmagic/color.rb', line 123 def initialize(value:) super(value: value.to_i.clamp(0, 255)) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value
119 120 121 |
# File 'lib/unmagic/color.rb', line 119 def value @value end |
Instance Method Details
#*(other) ⇒ Component
Returns New component.
141 142 143 |
# File 'lib/unmagic/color.rb', line 141 def *(other) self.class.new(value: value * other.to_f) end |
#+(other) ⇒ Component
Returns New component.
153 154 155 |
# File 'lib/unmagic/color.rb', line 153 def +(other) self.class.new(value: value + other.to_f) end |
#-(other) ⇒ Component
Returns New component.
159 160 161 |
# File 'lib/unmagic/color.rb', line 159 def -(other) self.class.new(value: value - other.to_f) end |
#/(other) ⇒ Component
Returns New component.
147 148 149 |
# File 'lib/unmagic/color.rb', line 147 def /(other) self.class.new(value: value / other.to_f) end |
#<=>(other) ⇒ Integer?
Returns Comparison result.
132 133 134 135 136 137 |
# File 'lib/unmagic/color.rb', line 132 def <=>(other) case other when Component, Numeric value <=> other.to_f end end |
#abs ⇒ Component
Returns Absolute value.
164 165 166 |
# File 'lib/unmagic/color.rb', line 164 def abs self.class.new(value: value.abs) end |
#to_f ⇒ Object
128 |
# File 'lib/unmagic/color.rb', line 128 def to_f = value.to_f |
#to_i ⇒ Object
127 |
# File 'lib/unmagic/color.rb', line 127 def to_i = value |