compass_point 1.1.0 → 1.2.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
- SHA1:
3
- metadata.gz: 05c895cb0f48a2861a8287f21fe2c065754f28a4
4
- data.tar.gz: 106814cdb998938219bff0e642fec12df38851f0
2
+ SHA256:
3
+ metadata.gz: cc5cb255e2b838ab24b075812b761e36917c57f0b7e5cc7c4fab65392a521c6b
4
+ data.tar.gz: 3c7a1523e8ddb807d515c0e7c5d848cf72ccbd81762b3946025d25ef08f1adfe
5
5
  SHA512:
6
- metadata.gz: d25f6cc323c2ea6f32487f71699e0d030803108381e84aea8c760ea6511222a0013a91c0e232098cc6c084d852da6e3aff9f525e28dea5b006cc01defd553fb9
7
- data.tar.gz: d47fea9fdc254a7aa5717f67011b03513bbc5ce901d45d7e90e8cae9dc361f21f77d73db3f620f261deac1a54f16d2c3da32afd477b8d568936453cc1163585c
6
+ metadata.gz: 5b9738cf946eea2ce210bf7bb33b5bd40c6f5237ac98fb009f3e65436f03ef62bb2c49e886830930952932c8e3872cb1b25be67fb590a4181d0a99e911fef4e6
7
+ data.tar.gz: 0c86a05cee019d0e38e25e877faa4a8d1713aee1a92d9f4024ae84f62a5bf7cb78c7b9323eab2fff2bb7f6a6d435afa964090ec66aa90b3c941379d99736d319
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  gemspec
2
2
  source 'https://rubygems.org'
3
3
 
4
-
5
4
  group :development, :test do
6
- gem 'rspec'
7
5
  gem 'guard'
8
6
  gem 'guard-rspec'
7
+ gem 'rspec'
8
+ gem 'rubocop'
9
9
  end
@@ -1,67 +1,76 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compass_point (1.0.1)
4
+ compass_point (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- celluloid (0.16.0)
10
- timers (~> 4.0.0)
11
- coderay (1.1.0)
12
- diff-lcs (1.2.5)
13
- ffi (1.9.8)
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ ffi (1.9.21)
14
13
  formatador (0.2.5)
15
- guard (2.12.5)
14
+ guard (2.14.2)
16
15
  formatador (>= 0.2.4)
17
- listen (~> 2.7)
18
- lumberjack (~> 1.0)
16
+ listen (>= 2.7, < 4.0)
17
+ lumberjack (>= 1.0.12, < 2.0)
19
18
  nenv (~> 0.1)
20
19
  notiffany (~> 0.0)
21
20
  pry (>= 0.9.12)
22
21
  shellany (~> 0.0)
23
22
  thor (>= 0.18.1)
24
23
  guard-compat (1.2.1)
25
- guard-rspec (4.5.0)
24
+ guard-rspec (4.7.3)
26
25
  guard (~> 2.1)
27
26
  guard-compat (~> 1.1)
28
27
  rspec (>= 2.99.0, < 4.0)
29
- hitimes (1.2.2)
30
- listen (2.10.0)
31
- celluloid (~> 0.16.0)
32
- rb-fsevent (>= 0.9.3)
33
- rb-inotify (>= 0.9)
34
- lumberjack (1.0.9)
35
- method_source (0.8.2)
36
- nenv (0.2.0)
37
- notiffany (0.0.6)
28
+ listen (3.1.5)
29
+ rb-fsevent (~> 0.9, >= 0.9.4)
30
+ rb-inotify (~> 0.9, >= 0.9.7)
31
+ ruby_dep (~> 1.2)
32
+ lumberjack (1.0.12)
33
+ method_source (0.9.0)
34
+ nenv (0.3.0)
35
+ notiffany (0.1.1)
38
36
  nenv (~> 0.1)
39
37
  shellany (~> 0.0)
40
- pry (0.10.1)
38
+ parallel (1.12.1)
39
+ parser (2.4.0.2)
40
+ ast (~> 2.3)
41
+ powerpack (0.1.1)
42
+ pry (0.11.3)
41
43
  coderay (~> 1.1.0)
42
- method_source (~> 0.8.1)
43
- slop (~> 3.4)
44
- rb-fsevent (0.9.4)
45
- rb-inotify (0.9.5)
46
- ffi (>= 0.5.0)
47
- rspec (3.2.0)
48
- rspec-core (~> 3.2.0)
49
- rspec-expectations (~> 3.2.0)
50
- rspec-mocks (~> 3.2.0)
51
- rspec-core (3.2.3)
52
- rspec-support (~> 3.2.0)
53
- rspec-expectations (3.2.1)
44
+ method_source (~> 0.9.0)
45
+ rainbow (3.0.0)
46
+ rb-fsevent (0.10.2)
47
+ rb-inotify (0.9.10)
48
+ ffi (>= 0.5.0, < 2)
49
+ rspec (3.7.0)
50
+ rspec-core (~> 3.7.0)
51
+ rspec-expectations (~> 3.7.0)
52
+ rspec-mocks (~> 3.7.0)
53
+ rspec-core (3.7.1)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-expectations (3.7.0)
54
56
  diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.2.0)
56
- rspec-mocks (3.2.1)
57
+ rspec-support (~> 3.7.0)
58
+ rspec-mocks (3.7.0)
57
59
  diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.2.0)
59
- rspec-support (3.2.2)
60
+ rspec-support (~> 3.7.0)
61
+ rspec-support (3.7.1)
62
+ rubocop (0.52.1)
63
+ parallel (~> 1.10)
64
+ parser (>= 2.4.0.2, < 3.0)
65
+ powerpack (~> 0.1)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (~> 1.0, >= 1.0.1)
69
+ ruby-progressbar (1.9.0)
70
+ ruby_dep (1.5.0)
60
71
  shellany (0.0.1)
61
- slop (3.6.0)
62
- thor (0.19.1)
63
- timers (4.0.1)
64
- hitimes
72
+ thor (0.20.0)
73
+ unicode-display_width (1.3.0)
65
74
 
66
75
  PLATFORMS
67
76
  ruby
@@ -71,6 +80,7 @@ DEPENDENCIES
71
80
  guard
72
81
  guard-rspec
73
82
  rspec
83
+ rubocop
74
84
 
75
85
  BUNDLED WITH
76
- 1.10.6
86
+ 1.16.1
@@ -1,8 +1,7 @@
1
- gemspec
2
1
  source 'https://rubygems.org'
3
2
 
3
+ gemspec
4
+
4
5
  group :test do
5
- gem 'rubysl', :platform => :rbx
6
6
  gem 'rspec'
7
- gem 'codeclimate-test-reporter', :require => false, :platform => :ruby
8
7
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006-2014 Keith Morrison <keithm@infused.org>
1
+ Copyright (c) 2015-2018 Keith Morrison <keithm@infused.org>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Compass Point
2
2
  [![Version](http://img.shields.io/gem/v/compass_point.svg?style=flat)](https://rubygems.org/gems/compass_point)
3
3
  [![Build Status](http://img.shields.io/travis/infused/compass_point/master.svg?style=flat)](http://travis-ci.org/infused/compass_point)
4
- [![Code Quality](http://img.shields.io/codeclimate/github/infused/compass_point.svg?style=flat)](https://codeclimate.com/github/infused/compass_point)
5
- [![Test Coverage](http://img.shields.io/codeclimate/coverage/github/infused/compass_point.svg?style=flat)](https://codeclimate.com/github/infused/compass_point)
6
4
  [![Dependency Status](http://img.shields.io/gemnasium/infused/compass_point.svg?style=flat)](https://gemnasium.com/infused/compass_point)
7
5
  [![Total Downloads](https://img.shields.io/gem/dt/compass_point.svg)](https://rubygems.org/gems/compass_point/)
8
6
 
@@ -18,7 +16,7 @@ A Ruby library for working with compass points.
18
16
 
19
17
  Compass Point is tested to work with the following versions of ruby:
20
18
 
21
- * MRI Ruby 2.0.x, 2.1.x, 2.2.x
19
+ * MRI Ruby 2.0.x, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x
22
20
  * JRuby 1.7.x
23
21
 
24
22
  ## Installation
@@ -29,20 +27,24 @@ Compass Point is tested to work with the following versions of ruby:
29
27
 
30
28
  ### Azimuth
31
29
 
32
- Given an abbreviation such as "NW" or "SE", `azimuth` will
30
+ Given an string such as "NW", "SE", "Northeast by east", or "N 20° W", `azimuth` will
33
31
  return the corresponding azimuth in degrees from 0 to 360:
34
32
 
35
33
  CompassPoint.azimuth('N') #=> 0.0
36
34
  CompassPoint.azimuth('S') #=> 180.0
37
35
  CompassPoint.azimuth('swbs') #=> 213.75
38
-
36
+ CompassPoint.azimuth('Northeast by east') #=> 56.25
37
+ CompassPoint.azimuth('N 20° W') #=> 340
39
38
 
40
39
  You can also get the minimum and maximum azimuths for any
41
40
  abbreviation with `min`, `max` and `min_max`:
42
41
 
43
42
  CompassPoint.min('E') #=> 84.38
44
43
  CompassPoint.max('E') #=> 95.62
44
+ CompassPoint.min('Northeast by east') #=> 50.63
45
+ CompassPoint.max('Northeast by east') #=> 61.87
45
46
  CompassPoint.min_max('E') #=> [84.38, 95.62]
47
+ CompassPoint.min_max('Northeast by east') #=> [50.63, 61.87]
46
48
 
47
49
  Get the full name for an abbreviation:
48
50
 
@@ -61,7 +63,7 @@ example:
61
63
 
62
64
  ## License
63
65
 
64
- Copyright (c) 2015 Keith Morrison <<keithm@infused.org>>
66
+ Copyright (c) 2015-2018 Keith Morrison <<keithm@infused.org>>
65
67
 
66
68
  Permission is hereby granted, free of charge, to any person
67
69
  obtaining a copy of this software and associated documentation
@@ -1,5 +1,5 @@
1
1
  class CompassPoint
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'.freeze
3
3
 
4
4
  POINTS = {
5
5
  n: {min: 354.38, mid: 0.0, max: 5.62, name: 'North'},
@@ -34,86 +34,103 @@ class CompassPoint
34
34
  nwbn: {min: 320.63, mid: 326.25, max: 331.87, name: 'Northwest by north'},
35
35
  nnw: {min: 331.88, mid: 337.50, max: 343.12, name: 'North northwest'},
36
36
  nbw: {min: 343.13, mid: 348.75, max: 354.37, name: 'North by west'}
37
- }
37
+ }.freeze
38
38
 
39
39
  class << self
40
- def azimuth(abbrev)
41
- point = find_point(abbrev)
42
- point && point[:mid]
40
+ def azimuth(s)
41
+ input = normalize_input(s)
42
+ if point = find_point(input)
43
+ point[:mid]
44
+ elsif match = input.match(/(n|s)\s(\d{1,3}).?\s(e|w)/)
45
+ base = if match[1] == 'n'
46
+ match[3] == 'w' ? 360 : 0
47
+ else
48
+ 180
49
+ end
50
+
51
+ adjust = match[2].to_i
52
+
53
+ operation = if (match[1] == 'n' && match[3] == 'w') || (match[1] == 's' && match[3] == 'e')
54
+ :-
55
+ else
56
+ :+
57
+ end
58
+
59
+ base.send(operation, adjust)
60
+ end
43
61
  end
44
62
 
45
- def min(abbrev)
46
- point = find_point(abbrev)
63
+ def min(s)
64
+ point = find_point(normalize_input(s))
47
65
  point && point[:min]
48
66
  end
49
67
 
50
- def max(abbrev)
51
- point = find_point(abbrev)
68
+ def max(s)
69
+ point = find_point(normalize_input(s))
52
70
  point && point[:max]
53
71
  end
54
72
 
55
- def min_max(abbrev)
56
- point = find_point(abbrev)
73
+ def min_max(s)
74
+ point = find_point(normalize_input(s))
57
75
  point && [point[:min], point[:max]]
58
76
  end
59
77
 
60
- def name(abbrev)
61
- point = find_point(abbrev)
78
+ def name(s)
79
+ point = find_point(normalize_input(s))
62
80
  point && point[:name]
63
81
  end
64
82
 
65
83
  def compass_quadrant_bearing(bearing)
66
84
  b = bearing.round
67
85
  case b
68
- when 0, 360
69
- 'N'
70
- when 90
71
- 'E'
72
- when 180
73
- 'S'
74
- when 270
75
- 'W'
86
+ when 0, 360 then 'N'
87
+ when 90 then 'E'
88
+ when 180 then 'S'
89
+ when 270 then 'W'
76
90
  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
+ generate_compass_quadrant_bearing(b)
91
92
  end
92
93
  end
93
94
 
94
95
  private
95
96
 
97
+ def generate_compass_quadrant_bearing(b)
98
+ s = []
99
+ s << north_or_south(b)
100
+ s << if north_or_south(b) == 'N'
101
+ east_or_west(b) == 'W' ? (360 - b).abs : b
102
+ else
103
+ (180 - b).abs
104
+ end.to_s
105
+ s.last << '°'
106
+ s << east_or_west(b)
107
+ s.join(' ')
108
+ end
109
+
96
110
  def north_or_south(bearing)
97
111
  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
112
+ (0..90).cover?(b.to_i) || (270..360).cover?(b.to_i) ? 'N' : 'S'
103
113
  end
104
114
 
105
115
  def east_or_west(bearing)
106
116
  b = bearing.round
107
- (180..360).include?(b.to_i) ? 'W' : 'E'
117
+ (180..360).cover?(b.to_i) ? 'W' : 'E'
118
+ end
119
+
120
+ def find_point(s)
121
+ find_point_by_abbrev(s) || find_point_by_name(s)
122
+ end
123
+
124
+ def find_point_by_abbrev(s)
125
+ POINTS[s.to_sym]
108
126
  end
109
127
 
110
- def find_point(abbrev)
111
- key = normalize_abbrev(abbrev)
112
- POINTS[key]
128
+ def find_point_by_name(s)
129
+ POINTS.values.find { |v| v[:name].downcase == s }
113
130
  end
114
131
 
115
- def normalize_abbrev(abbrev)
116
- abbrev.to_s.downcase.to_sym
132
+ def normalize_input(name)
133
+ name.to_s.strip.squeeze(' ').downcase
117
134
  end
118
135
  end
119
136
  end
@@ -7,6 +7,13 @@ describe CompassPoint do
7
7
  expect(CompassPoint.azimuth(:nw)).to eq 315.0
8
8
  expect(CompassPoint.azimuth('sbw')).to eq 191.25
9
9
  expect(CompassPoint.azimuth('X')).to be_nil
10
+ expect(CompassPoint.azimuth('Northeast by east')).to eq 56.25
11
+ expect(CompassPoint.azimuth('N 27° E')).to eq 27
12
+ expect(CompassPoint.azimuth('S 77° E')).to eq 103
13
+ expect(CompassPoint.azimuth('S 2° E')).to eq 178
14
+ expect(CompassPoint.azimuth('N 77° W')).to eq 283
15
+ expect(CompassPoint.azimuth('N 20 W')).to eq 340
16
+ expect(CompassPoint.azimuth('S 30° W')).to eq 210
10
17
  end
11
18
  end
12
19
 
@@ -16,6 +23,7 @@ describe CompassPoint do
16
23
  expect(CompassPoint.min(:nw)).to eq 309.38
17
24
  expect(CompassPoint.min('sbw')).to eq 185.63
18
25
  expect(CompassPoint.min('X')).to be_nil
26
+ expect(CompassPoint.min('Northeast by east')).to eq 50.63
19
27
  end
20
28
  end
21
29
 
@@ -25,6 +33,7 @@ describe CompassPoint do
25
33
  expect(CompassPoint.max(:nw)).to eq 320.62
26
34
  expect(CompassPoint.max('sbw')).to eq 196.87
27
35
  expect(CompassPoint.max('X')).to be_nil
36
+ expect(CompassPoint.max('Northeast by east')).to eq 61.87
28
37
  end
29
38
  end
30
39
 
@@ -34,6 +43,7 @@ describe CompassPoint do
34
43
  expect(CompassPoint.min_max(:nw)).to eq [309.38, 320.62]
35
44
  expect(CompassPoint.min_max('sbw')).to eq [185.63, 196.87]
36
45
  expect(CompassPoint.min_max('X')).to be_nil
46
+ expect(CompassPoint.min_max('Northeast by east')).to eq [50.63, 61.87]
37
47
  end
38
48
  end
39
49
 
@@ -1,9 +1,3 @@
1
- begin
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
- rescue LoadError
5
- end
6
-
7
1
  require 'compass_point'
8
2
  require 'rspec'
9
3
 
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.1.0
4
+ version: 1.2.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-10-27 00:00:00.000000000 Z
11
+ date: 2018-02-08 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.gemspec
29
28
  - lib/compass_point.rb
30
29
  - spec/compass_point_spec.rb
31
30
  - spec/spec_helper.rb
@@ -50,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
49
  version: 1.3.0
51
50
  requirements: []
52
51
  rubyforge_project:
53
- rubygems_version: 2.4.5
52
+ rubygems_version: 2.7.3
54
53
  signing_key:
55
54
  specification_version: 4
56
55
  summary: A Ruby library for working with compass points
@@ -1,23 +0,0 @@
1
- lib = File.expand_path('../lib/', __FILE__)
2
- $:.unshift lib unless $:.include?(lib)
3
- require 'compass_point'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'compass_point'
7
- s.version = CompassPoint::VERSION
8
- s.authors = ['Keith Morrison']
9
- s.email = 'keithm@infused.org'
10
- s.homepage = 'http://github.com/infused/compass_point'
11
- s.summary = 'A Ruby library for working with compass points'
12
- s.description = 'A Ruby library for working with compass points'
13
- s.license = 'MIT'
14
-
15
- s.rdoc_options = ['--charset=UTF-8']
16
- s.extra_rdoc_files = ['README.md', 'LICENSE']
17
- s.files = Dir['[A-Z]*', '{lib,spec}/**/*', 'compass_points.gemspec']
18
- s.test_files = Dir.glob('spec/**/*_spec.rb')
19
- s.require_paths = ['lib']
20
-
21
- s.required_ruby_version = '>= 1.9.3'
22
- s.required_rubygems_version = '>= 1.3.0'
23
- end