Class: Color::XYZ
- Inherits:
-
Object
- Object
- Color::XYZ
- Defined in:
- lib/color/xyz.rb
Instance Attribute Summary collapse
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
- #convert(value) ⇒ Object
-
#initialize(color) ⇒ XYZ
constructor
A new instance of XYZ.
- #to_a ⇒ Object
- #var_b ⇒ Object
- #var_g ⇒ Object
- #var_r ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
Constructor Details
#initialize(color) ⇒ XYZ
Returns a new instance of XYZ.
10 11 12 13 14 |
# File 'lib/color/xyz.rb', line 10 def initialize(color) @r = color.r.to_f @g = color.g.to_f @b = color.b.to_f end |
Instance Attribute Details
#b ⇒ Object (readonly)
Returns the value of attribute b.
4 5 6 |
# File 'lib/color/xyz.rb', line 4 def b @b end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
4 5 6 |
# File 'lib/color/xyz.rb', line 4 def g @g end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
4 5 6 |
# File 'lib/color/xyz.rb', line 4 def r @r end |
Class Method Details
.from_rgb(rgb_color) ⇒ Object
6 7 8 |
# File 'lib/color/xyz.rb', line 6 def self.from_rgb(rgb_color) self.new(rgb_color) end |
Instance Method Details
#convert(value) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/color/xyz.rb', line 44 def convert(value) variable = (send(value) / 255.0) if ( variable > 0.04045) variable = ( ( variable + 0.055) / 1.055) ** 2.4 else variable = variable / 12.92 end variable * 100 end |
#to_a ⇒ Object
16 17 18 |
# File 'lib/color/xyz.rb', line 16 def to_a [x, y, z] end |
#var_b ⇒ Object
40 41 42 |
# File 'lib/color/xyz.rb', line 40 def var_b @var_b ||= convert(:b) end |
#var_g ⇒ Object
36 37 38 |
# File 'lib/color/xyz.rb', line 36 def var_g @var_g ||= convert(:g) end |
#var_r ⇒ Object
32 33 34 |
# File 'lib/color/xyz.rb', line 32 def var_r @var_r ||= convert(:r) end |
#x ⇒ Object
20 21 22 |
# File 'lib/color/xyz.rb', line 20 def x @x ||= ( var_r * 0.4124 + var_g * 0.3576 + var_b * 0.1805 ) end |
#y ⇒ Object
24 25 26 |
# File 'lib/color/xyz.rb', line 24 def y @y ||= ( var_r * 0.2126 + var_g * 0.7152 + var_b * 0.0722) end |
#z ⇒ Object
28 29 30 |
# File 'lib/color/xyz.rb', line 28 def z @z ||= ( var_r * 0.0193 + var_g * 0.1192 + var_b * 0.9505) end |