Module: CompassRose::RoseUtils

Included in:
CompassRose
Defined in:
lib/compass_rose/ranges.rb

Overview

RoseUtils module is used to build the RANGES constant below

Class Method Summary collapse

Class Method Details

.bearing_nonzero(rose_map, last_bearing) ⇒ Object



38
39
40
41
42
# File 'lib/compass_rose/ranges.rb', line 38

def self.bearing_nonzero(rose_map, last_bearing)
  low = format('%.2f', last_bearing + 0.01).to_f
  last_bearing = high = format('%.2f', last_bearing + rose_map[:s]).to_f
  [low, high, last_bearing]
end

.bearing_zero(rose_map) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/compass_rose/ranges.rb', line 28

def self.bearing_zero(rose_map)
  low = format(
    '%.2f', (360.0 - (rose_map[:s] / 2.0)) + 0.01
  ).to_f
  last_bearing = high = format(
    '%.2f', 0.00 + (rose_map[:s] / 2.0)
  ).to_f
  [low, high, last_bearing]
end

.build_rose(rose_map) ⇒ Object



9
10
11
12
13
# File 'lib/compass_rose/ranges.rb', line 9

def self.build_rose(rose_map)
  last_bearing = 0.00
  h = hashit(rose_map, last_bearing)
  h
end

.hashit(rose_map, last_bearing) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/compass_rose/ranges.rb', line 15

def self.hashit(rose_map, last_bearing)
  h = {}
  rose_map[:d].each do |b|
    if last_bearing == 0
      low, high, last_bearing = bearing_zero(rose_map)
    else
      low, high, last_bearing = bearing_nonzero(rose_map, last_bearing)
    end
    h[b] = { low: low, high: high }
  end
  h
end