Class: ColorSpaceConverter::ColorSpace

Inherits:
Object
  • Object
show all
Includes:
Compute
Defined in:
lib/color_space_converter/color_space.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Compute

hex2rgb, hsv2rgb, lab2rgb, lab2xyz, rgb2hex, rgb2hsv, rgb2lab, rgb2xyz, xyz2lab, xyz2rgb

Constructor Details

#initialize(space, e1, e2, e3) ⇒ ColorSpace

Returns a new instance of ColorSpace.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/color_space_converter/color_space.rb', line 10

def initialize(space, e1, e2, e3)
  @init_space = space
  if space == 'rgb'
    @rgb = [e1, e2, e3]
  elsif space == 'xyz'
    @xyz = [e1, e2, e3]
  elsif space == 'lab'
    @lab = [e1, e2, e3]
  else
    @init_space = ''
    puts ColorSpaceConverter::Const::ERROR_USAGE
  end
end

Instance Attribute Details

#hexObject (readonly)

Returns the value of attribute hex.



6
7
8
# File 'lib/color_space_converter/color_space.rb', line 6

def hex
  @hex
end

#labObject (readonly)

Returns the value of attribute lab.



6
7
8
# File 'lib/color_space_converter/color_space.rb', line 6

def lab
  @lab
end

#rgbObject (readonly)

Returns the value of attribute rgb.



6
7
8
# File 'lib/color_space_converter/color_space.rb', line 6

def rgb
  @rgb
end

#xyzObject (readonly)

Returns the value of attribute xyz.



6
7
8
# File 'lib/color_space_converter/color_space.rb', line 6

def xyz
  @xyz
end

Instance Method Details

#calc_lab(x_n: 100, y_n: 100, z_n: 100) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/color_space_converter/color_space.rb', line 42

def calc_lab(x_n: 100, y_n: 100, z_n: 100)
  if @rgb
    @lab = rgb2lab(@rgb[0], @rgb[1], @rgb[2], x_n: x_n, y_n: y_n, z_n: z_n)
  elsif @xyz
    @lab = xyz2lab(@xyz[0], @xyz[1], @xyz[2], x_n: x_n, y_n: y_n, z_n: z_n)
  end
  @lab
end

#calc_rgb(x_n: 100, y_n: 100, z_n: 100) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/color_space_converter/color_space.rb', line 24

def calc_rgb(x_n: 100, y_n: 100, z_n: 100)
  if @xyz
    @rgb = xyz2rgb(@xyz[0], @xyz[1], @rgb[2])
  elsif @lab
    @rgb = lab2rgb(@lab[0], @lab[1], @lab[2], x_n: x_n, y_n: y_n, z_n: z_n)
  end
  @rgb
end

#calc_xyz(x_n: 100, y_n: 100, z_n: 100) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/color_space_converter/color_space.rb', line 33

def calc_xyz(x_n: 100, y_n: 100, z_n: 100)
  if @rgb
    @xyz = rgb2xyz(@rgb[0], @rgb[1], @rgb[2])
  elsif @lab
    @xyz = lab2xyz(@lab[0], @lab[1], @lab[2], x_n: x_n, y_n: y_n, z_n: z_n)
  end
  @xyz
end