I just came across the need to do this.
My version (in jruby)
# Given the direction in degrees, return the direction abbreviation
def direction_name(degree)
degree = (degree + 11.25) % 360
index = (degree.to_f / 22.5).floor
%w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW][index]
end