Class: Abachrome::ColorModels::RGB
- Inherits:
-
Object
- Object
- Abachrome::ColorModels::RGB
- Defined in:
- lib/abachrome/color_models/rgb.rb
Class Method Summary collapse
-
.normalize(r, g, b) ⇒ Array<AbcDecimal>
Normalizes RGB color component values to the [0,1] range.
Class Method Details
.normalize(r, g, b) ⇒ Array<AbcDecimal>
Normalizes RGB color component values to the [0,1] range.
if string without suffix or numeric > 1, interpreted as 0-255 range value; if numeric ≤ 1, used directly. each in the range [0,1].
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/abachrome/color_models/rgb.rb', line 33 def normalize(r, g, b) [r, g, b].map do |value| case value when String if value.end_with?("%") AbcDecimal(value.chomp("%")) / AbcDecimal(100) else AbcDecimal(value) / AbcDecimal(255) end when Numeric if value > 1 AbcDecimal(value) / AbcDecimal(255) else AbcDecimal(value) end end end end |