I needed to convert RGB values into HSB. I found a very old gem, colour-tools, which sadly only converts to HSL. So I rewrote Alvein’s C implementation to calculate it in Ruby. Hope it saves someone time.
Inputs: red, green and blue values as integers between 0 and 255. Outputs according to HSB convention: hue as degrees (up to 360), saturation and brightness as percentages.