compass_point 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -0
- data/README.md +16 -5
- data/lib/compass_point.rb +44 -1
- data/spec/compass_point_spec.rb +18 -0
- metadata +3 -4
- data/compass_point-1.0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05c895cb0f48a2861a8287f21fe2c065754f28a4
|
4
|
+
data.tar.gz: 106814cdb998938219bff0e642fec12df38851f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d25f6cc323c2ea6f32487f71699e0d030803108381e84aea8c760ea6511222a0013a91c0e232098cc6c084d852da6e3aff9f525e28dea5b006cc01defd553fb9
|
7
|
+
data.tar.gz: d47fea9fdc254a7aa5717f67011b03513bbc5ce901d45d7e90e8cae9dc361f21f77d73db3f620f261deac1a54f16d2c3da32afd477b8d568936453cc1163585c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,11 @@
|
|
4
4
|
[](https://codeclimate.com/github/infused/compass_point)
|
5
5
|
[](https://codeclimate.com/github/infused/compass_point)
|
6
6
|
[](https://gemnasium.com/infused/compass_point)
|
7
|
+
[](https://rubygems.org/gems/compass_point/)
|
7
8
|
|
8
|
-
A Ruby library for working with compass points
|
9
|
+
A Ruby library for working with compass points.
|
10
|
+
|
11
|
+

|
9
12
|
|
10
13
|
* Project page: <http://github.com/infused/compass_point>
|
11
14
|
* API Documentation: <http://rubydoc.info/github/infused/compass_point/>
|
@@ -15,9 +18,8 @@ A Ruby library for working with compass points
|
|
15
18
|
|
16
19
|
Compass Point is tested to work with the following versions of ruby:
|
17
20
|
|
18
|
-
* MRI Ruby
|
21
|
+
* MRI Ruby 2.0.x, 2.1.x, 2.2.x
|
19
22
|
* JRuby 1.7.x
|
20
|
-
* Rubinius 2.1+
|
21
23
|
|
22
24
|
## Installation
|
23
25
|
|
@@ -25,11 +27,11 @@ Compass Point is tested to work with the following versions of ruby:
|
|
25
27
|
|
26
28
|
## Basic Usage
|
27
29
|
|
30
|
+
### Azimuth
|
31
|
+
|
28
32
|
Given an abbreviation such as "NW" or "SE", `azimuth` will
|
29
33
|
return the corresponding azimuth in degrees from 0 to 360:
|
30
34
|
|
31
|
-
require 'compass_point'
|
32
|
-
|
33
35
|
CompassPoint.azimuth('N') #=> 0.0
|
34
36
|
CompassPoint.azimuth('S') #=> 180.0
|
35
37
|
CompassPoint.azimuth('swbs') #=> 213.75
|
@@ -48,6 +50,15 @@ Get the full name for an abbreviation:
|
|
48
50
|
CompassPoint.name('SEbS') #=> "Southeast by south"
|
49
51
|
|
50
52
|
|
53
|
+
### Compass Quadrant Bearing
|
54
|
+
|
55
|
+
Given an azimuth, calculate the compass quadrant bearing. For
|
56
|
+
example:
|
57
|
+
|
58
|
+
CompassPoint.compass_quadrant_bearing(103) #=> "S 77° E"
|
59
|
+
CompassPoint.compass_quadrant_bearing(340) #=> "N 20° W"
|
60
|
+
CompassPoint.compass_quadrant_bearing(0) #=> "N"
|
61
|
+
|
51
62
|
## License
|
52
63
|
|
53
64
|
Copyright (c) 2015 Keith Morrison <<keithm@infused.org>>
|
data/lib/compass_point.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class CompassPoint
|
2
|
-
VERSION = '1.0
|
2
|
+
VERSION = '1.1.0'
|
3
3
|
|
4
4
|
POINTS = {
|
5
5
|
n: {min: 354.38, mid: 0.0, max: 5.62, name: 'North'},
|
@@ -62,8 +62,51 @@ class CompassPoint
|
|
62
62
|
point && point[:name]
|
63
63
|
end
|
64
64
|
|
65
|
+
def compass_quadrant_bearing(bearing)
|
66
|
+
b = bearing.round
|
67
|
+
case b
|
68
|
+
when 0, 360
|
69
|
+
'N'
|
70
|
+
when 90
|
71
|
+
'E'
|
72
|
+
when 180
|
73
|
+
'S'
|
74
|
+
when 270
|
75
|
+
'W'
|
76
|
+
else
|
77
|
+
s = []
|
78
|
+
s << north_or_south(b)
|
79
|
+
if north_or_south(b) == 'N'
|
80
|
+
if east_or_west(b) == 'W'
|
81
|
+
s << (360 - b).abs.to_s
|
82
|
+
else
|
83
|
+
s << b.to_s
|
84
|
+
end
|
85
|
+
else
|
86
|
+
s << (180 - b).abs.to_s
|
87
|
+
end
|
88
|
+
s.last << '°'
|
89
|
+
s << east_or_west(b)
|
90
|
+
s.join(' ')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
65
94
|
private
|
66
95
|
|
96
|
+
def north_or_south(bearing)
|
97
|
+
b = bearing.round
|
98
|
+
if (0..90).include?(b.to_i) || (270..360).include?(b.to_i)
|
99
|
+
'N'
|
100
|
+
else
|
101
|
+
'S'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def east_or_west(bearing)
|
106
|
+
b = bearing.round
|
107
|
+
(180..360).include?(b.to_i) ? 'W' : 'E'
|
108
|
+
end
|
109
|
+
|
67
110
|
def find_point(abbrev)
|
68
111
|
key = normalize_abbrev(abbrev)
|
69
112
|
POINTS[key]
|
data/spec/compass_point_spec.rb
CHANGED
@@ -43,4 +43,22 @@ describe CompassPoint do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
describe '.compass_quadrant_bearing' do
|
47
|
+
it 'is' do
|
48
|
+
expect(CompassPoint.compass_quadrant_bearing(0)).to eq 'N'
|
49
|
+
expect(CompassPoint.compass_quadrant_bearing(27)).to eq 'N 27° E'
|
50
|
+
expect(CompassPoint.compass_quadrant_bearing(27.4)).to eq 'N 27° E'
|
51
|
+
expect(CompassPoint.compass_quadrant_bearing(27.7)).to eq 'N 28° E'
|
52
|
+
expect(CompassPoint.compass_quadrant_bearing(90)).to eq 'E'
|
53
|
+
expect(CompassPoint.compass_quadrant_bearing(103)).to eq 'S 77° E'
|
54
|
+
expect(CompassPoint.compass_quadrant_bearing(178)).to eq 'S 2° E'
|
55
|
+
expect(CompassPoint.compass_quadrant_bearing(180)).to eq 'S'
|
56
|
+
expect(CompassPoint.compass_quadrant_bearing(210)).to eq 'S 30° W'
|
57
|
+
expect(CompassPoint.compass_quadrant_bearing(270)).to eq 'W'
|
58
|
+
expect(CompassPoint.compass_quadrant_bearing(283)).to eq 'N 77° W'
|
59
|
+
expect(CompassPoint.compass_quadrant_bearing(340)).to eq 'N 20° W'
|
60
|
+
expect(CompassPoint.compass_quadrant_bearing(360)).to eq 'N'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
46
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compass_point
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby library for working with compass points
|
14
14
|
email: keithm@infused.org
|
@@ -25,7 +25,6 @@ files:
|
|
25
25
|
- LICENSE
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
|
-
- compass_point-1.0.2.gem
|
29
28
|
- compass_point.gemspec
|
30
29
|
- lib/compass_point.rb
|
31
30
|
- spec/compass_point_spec.rb
|
@@ -51,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
50
|
version: 1.3.0
|
52
51
|
requirements: []
|
53
52
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.4.
|
53
|
+
rubygems_version: 2.4.5
|
55
54
|
signing_key:
|
56
55
|
specification_version: 4
|
57
56
|
summary: A Ruby library for working with compass points
|
data/compass_point-1.0.2.gem
DELETED
Binary file
|