compass_point 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 727e4aee92e7e31485a86c41370debef6bf3566b
4
- data.tar.gz: 9387617d7472f9189340bec7358f8ac8d51d8d57
3
+ metadata.gz: 05c895cb0f48a2861a8287f21fe2c065754f28a4
4
+ data.tar.gz: 106814cdb998938219bff0e642fec12df38851f0
5
5
  SHA512:
6
- metadata.gz: 98c507d29befc7025b5f9437723fcda5d22e7a69cbe023db5b9495b69100212c02ea8a55aaf4e6690eb5cda538feab2f2e12d17a4ad9d072055fe767dbf88dcd
7
- data.tar.gz: 2af0ff531e642802bb8f2ce1204eeb3f69bc5449bdd936d5533373d1412fbe8047c97228a077c712e6ce60eeeb513d8cdef99a93cf1f10a61abb7c244d960dd4
6
+ metadata.gz: d25f6cc323c2ea6f32487f71699e0d030803108381e84aea8c760ea6511222a0013a91c0e232098cc6c084d852da6e3aff9f525e28dea5b006cc01defd553fb9
7
+ data.tar.gz: d47fea9fdc254a7aa5717f67011b03513bbc5ce901d45d7e90e8cae9dc361f21f77d73db3f620f261deac1a54f16d2c3da32afd477b8d568936453cc1163585c
@@ -71,3 +71,6 @@ DEPENDENCIES
71
71
  guard
72
72
  guard-rspec
73
73
  rspec
74
+
75
+ BUNDLED WITH
76
+ 1.10.6
data/README.md CHANGED
@@ -4,8 +4,11 @@
4
4
  [![Code Quality](http://img.shields.io/codeclimate/github/infused/compass_point.svg?style=flat)](https://codeclimate.com/github/infused/compass_point)
5
5
  [![Test Coverage](http://img.shields.io/codeclimate/coverage/github/infused/compass_point.svg?style=flat)](https://codeclimate.com/github/infused/compass_point)
6
6
  [![Dependency Status](http://img.shields.io/gemnasium/infused/compass_point.svg?style=flat)](https://gemnasium.com/infused/compass_point)
7
+ [![Total Downloads](https://img.shields.io/gem/dt/compass_point.svg)](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
+ ![Compass Rose](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Compass_Rose_English_North.svg/237px-Compass_Rose_English_North.svg.png)
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 1.9.3, 2.0.x, 2.1.x, 2.2.x
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>>
@@ -1,5 +1,5 @@
1
1
  class CompassPoint
2
- VERSION = '1.0.3'
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]
@@ -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.3
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-04-23 00:00:00.000000000 Z
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.6
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
Binary file