ruby - Convert orientation (N, S, SE, SSE etc) to bearing angle -
is there functionality in ruby or gem convert string orientation (examples in title) bearing in degrees, bearing defined follows?
a numerical value representing direction in degrees, true north @ 0° , progressing clockwise.
this works 8 main cardinal directions:
def cardinal_direction_degrees(s) h = {n: 0, ne: 45, e: 90, se: 135, s: 180, sw: 225, w: 270, nw: 315} h[s.to_s.downcase.to_sym] end puts cardinal_direction_degrees('n') #=> 0 puts cardinal_direction_degrees('sw') #=> 225
you can add remaining directions adding more elements hash.