So I'm trying to write a converter for HSL to RGB (and eventually into hex) I'm following this colorspace conversion theory and I seem to be stuck on step 6

Now we need to do up to 3 tests to select the correct formula for each color channel. Let’s start with Red.

test 1 – If 6 x temporary_R is smaller then 1, Red = temporary_2 + (temporary_1 – temporary_2) x 6 x temporary_R In the case the first test is larger then 1 check the following

test 2 – If 2 x temporary_R is smaller then 1, Red = temporary_1 In the case the second test also is larger then 1 do the following

test 3 – If 3 x temporary_R is smaller then 2, Red = temporary_2 + (temporary_1 – temporary_2) x (0.666 – temporary_R) x 6 In the case the third test also is larger then 2 you do the following

Red = temporary_2

Ok lets do it for our Red value

6 x temporary_R = 6 x 0.869 = 5.214, so it’s larger then 1, we need to do test 2 2 x temporary_R = 2 x 0.869 = 1.738, it’s also larger then 1, we need to do test 3 3 x temporary_R = 3 x 0.869 = 2.607, it’s larger then 2, so we go for the last formula Red = temporary_2 = 0.0924 which rounded down is 0.09, which is a number we recognize from the RGB to HSL conversion

So far I've monkey patched a function to take my HSL colours

```
def toRGB(hue, sat, lum)
temp_1 =
case lum
when lum < 0.0
lum x (1.0 * sat)
when lum > 0.0
(lum + sat) - lum
end
temp_2 = (2 * lum) - temp_1.to_f
h = (hue/360.0).round(4)
temp_r = (h + 0.333).round(4)
temp_r = temp_r + 1 if temp_r < 0
temp_r = temp_r - 1 if temp_r > 1
temp_g = h
temp_b = (h - 0.333).round(4)
temp_b = temp_b + 1 if temp_b < 0
temp_b = temp_b - 1 if temp_b > 1
red =
#test 1
#test 2
#test 3
"#{red}"
end
```

I was trying to use a `case`

statement

```
red =
case temp_r
when 6 * temp_r < 1
temp_2 + (temp_1 - temp_2) * 6 * temp_r
when 2 * temp_r < 1
temp_1
when 3 * temp_r < 2
temp_2 + (temp_1 - temp_2) * (0.666 - temp_r * 6)
end
```

but then I started re-reading the instructions and now I can't really see a way to do what I need in ruby. Maybe I'm over-thinking it.

If you want to see the rest of my code in context you can see it here