compass_point 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.travis +8 -0
- data/README.md +12 -3
- data/Rakefile +18 -0
- data/compass_point-1.0.0.gem +0 -0
- data/lib/compass_point.rb +22 -4
- data/spec/compass_point_spec.rb +28 -2
- data/spec/spec_helper.rb +6 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e46d4553f9de5ae11fab63be88ffea5b32b21b1
|
4
|
+
data.tar.gz: 9103ff880351b8f3469e912d27fcd351dc9b34e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3060a1b29300b947838f00e6d4083f0985b11bbc90b16c0840addf77bd83f4e2e58c205708cbe4e3e551bb91aa78788bb2090bb25057e49935ac06cb8dc64f85
|
7
|
+
data.tar.gz: 03e91329bc09f28df2bff07a1584fbbe1f5b1cbe4fa422d9a966bd03c0d7e76aad81071df579abde78ac300875ec1f8b453ce97c30adcf2e0c9fc04c1f5387e8
|
data/Gemfile.travis
ADDED
data/README.md
CHANGED
@@ -21,12 +21,13 @@ Compass Point is tested to work with the following versions of ruby:
|
|
21
21
|
|
22
22
|
## Installation
|
23
23
|
|
24
|
-
|
25
|
-
gem install compass_point
|
26
|
-
```
|
24
|
+
gem install compass_point
|
27
25
|
|
28
26
|
## Basic Usage
|
29
27
|
|
28
|
+
Given an abbreviation such as "NW" or "SE", `azimuth` will
|
29
|
+
return the corresponding azimuth in degrees from 0 to 360:
|
30
|
+
|
30
31
|
require 'compass_point'
|
31
32
|
|
32
33
|
CompassPoint.azimuth('N') #=> 0.0
|
@@ -34,6 +35,14 @@ gem install compass_point
|
|
34
35
|
CompassPoint.azimuth('swbs') #=> 213.75
|
35
36
|
|
36
37
|
|
38
|
+
You can also get the minimum and maximum azimuths for any
|
39
|
+
abbreviation with `min`, `max` and `min_max`:
|
40
|
+
|
41
|
+
CompassPoint.min('E') #=> 84.38
|
42
|
+
CompassPoint.max('E') #=> 95.62
|
43
|
+
CompassPoint.min_max('E') #=> [84.38, 95.62]
|
44
|
+
|
45
|
+
|
37
46
|
## License
|
38
47
|
|
39
48
|
Copyright (c) 2015 Keith Morrison <<keithm@infused.org>>
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup(:default, :development)
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new :spec do |t|
|
6
|
+
t.rspec_opts = %w(--color)
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new :specdoc do |t|
|
10
|
+
t.rspec_opts = %w(-fl)
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
14
|
+
|
15
|
+
desc "Open an irb session preloaded with this library"
|
16
|
+
task :console do
|
17
|
+
sh "irb -rubygems -I lib -r compass_point.rb"
|
18
|
+
end
|
Binary file
|
data/lib/compass_point.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class CompassPoint
|
2
|
-
VERSION = '1.0.
|
2
|
+
VERSION = '1.0.1'
|
3
3
|
|
4
4
|
POINTS = {
|
5
5
|
n: {min: 354.38, mid: 0.0, max: 5.62},
|
@@ -37,15 +37,33 @@ class CompassPoint
|
|
37
37
|
}
|
38
38
|
|
39
39
|
class << self
|
40
|
-
def azimuth(
|
41
|
-
key =
|
40
|
+
def azimuth(abbreviation)
|
41
|
+
key = normalize_abbreviation(abbreviation)
|
42
42
|
point = POINTS[key]
|
43
43
|
point && point[:mid]
|
44
44
|
end
|
45
45
|
|
46
|
+
def min(abbreviation)
|
47
|
+
key = normalize_abbreviation(abbreviation)
|
48
|
+
point = POINTS[key]
|
49
|
+
point && point[:min]
|
50
|
+
end
|
51
|
+
|
52
|
+
def max(abbreviation)
|
53
|
+
key = normalize_abbreviation(abbreviation)
|
54
|
+
point = POINTS[key]
|
55
|
+
point && point[:max]
|
56
|
+
end
|
57
|
+
|
58
|
+
def min_max(abbreviation)
|
59
|
+
key = normalize_abbreviation(abbreviation)
|
60
|
+
point = POINTS[key]
|
61
|
+
point && [point[:min], point[:max]]
|
62
|
+
end
|
63
|
+
|
46
64
|
private
|
47
65
|
|
48
|
-
def
|
66
|
+
def normalize_abbreviation(compass_point)
|
49
67
|
compass_point.to_s.downcase.to_sym
|
50
68
|
end
|
51
69
|
end
|
data/spec/compass_point_spec.rb
CHANGED
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe CompassPoint do
|
4
4
|
describe '.azimuth' do
|
5
|
-
|
6
|
-
it 'returns mid point' do
|
5
|
+
it 'returns mid point in degrees' do
|
7
6
|
expect(CompassPoint.azimuth('N')).to eq 0.0
|
8
7
|
expect(CompassPoint.azimuth(:nw)).to eq 315.0
|
9
8
|
expect(CompassPoint.azimuth('sbw')).to eq 191.25
|
@@ -11,4 +10,31 @@ describe CompassPoint do
|
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
13
|
+
describe '.min' do
|
14
|
+
it 'returns min point in degrees' do
|
15
|
+
expect(CompassPoint.min('N')).to eq 354.38
|
16
|
+
expect(CompassPoint.min(:nw)).to eq 309.38
|
17
|
+
expect(CompassPoint.min('sbw')).to eq 185.63
|
18
|
+
expect(CompassPoint.min('X')).to be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.max' do
|
23
|
+
it 'returns max point in degrees' do
|
24
|
+
expect(CompassPoint.max('N')).to eq 5.62
|
25
|
+
expect(CompassPoint.max(:nw)).to eq 320.62
|
26
|
+
expect(CompassPoint.max('sbw')).to eq 196.87
|
27
|
+
expect(CompassPoint.max('X')).to be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.min_max' do
|
32
|
+
it 'returns [min, max]' do
|
33
|
+
expect(CompassPoint.min_max('N')).to eq [354.38, 5.62]
|
34
|
+
expect(CompassPoint.min_max(:nw)).to eq [309.38, 320.62]
|
35
|
+
expect(CompassPoint.min_max('sbw')).to eq [185.63, 196.87]
|
36
|
+
expect(CompassPoint.min_max('X')).to be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
14
40
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
@@ -20,9 +20,12 @@ extra_rdoc_files:
|
|
20
20
|
files:
|
21
21
|
- Gemfile
|
22
22
|
- Gemfile.lock
|
23
|
+
- Gemfile.travis
|
23
24
|
- Guardfile
|
24
25
|
- LICENSE
|
25
26
|
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- compass_point-1.0.0.gem
|
26
29
|
- compass_point.gemspec
|
27
30
|
- lib/compass_point.rb
|
28
31
|
- spec/compass_point_spec.rb
|