geohash_ruby 1.0.1 → 1.0.2

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: 94a7547a11cbb73e125717ba559115319c522c8c
4
- data.tar.gz: 1ea423443e102b1d1d00801075f1504cf451b337
3
+ metadata.gz: 58b261ba8d6019211aff6d78da4ae095c05837cf
4
+ data.tar.gz: 310de7511ed3db7027839a1c91f4c788f6076503
5
5
  SHA512:
6
- metadata.gz: 1cd57054c144be8395c8d3cde51efa7abe34894830794afd91a972015a94a8d3c01be496c31b19d4fc6d9891daaee72aff2914aa3a8d43e9429e5d04454b2711
7
- data.tar.gz: ea0d0afd0d724e75f94be4ad6a908cc7b21f7f0b104984d1c8b373e0dc9e7b322ca8342b086a0beae05c731bc675743a16f80bd472b3f23eb614f00ecb187d55
6
+ metadata.gz: 974eefbf2b3872546c470196188d0442bb8889b45dda737520d87bae5e48fccb558635d685c0d93850b0d0041bd852e0001e362e8089c02c2c051773ef51ef36
7
+ data.tar.gz: f234b3d48872abea48e849a475def66842e39ff9e240c3f5940d15ce26d742daeb8d6d8ba795291c5ff0f61aa503286bc99b661a3a3f4c24f79455c5ce277e3b
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
- GeoHash
1
+ Geohash
2
2
  =======
3
3
 
4
- GeoHash en/decode library written in ruby.
5
-
6
- Based on [masuidrive/pr_geohash](https://github.com/masuidrive/pr_geohash), which isn't good implementation.
4
+ Geohash en/decode library written in Ruby.
7
5
 
8
6
 
9
7
  Install
@@ -20,31 +18,31 @@ Usage
20
18
  ### Encode latitude and longitude into geohash
21
19
 
22
20
  ```ruby
23
- GeoHash.encode 47.6062095, -122.3320708
21
+ Geohash.encode 47.6062095, -122.3320708
24
22
  #=> "c23nb62w20st"
25
23
 
26
- GeoHash.encode 47.6062095, -122.3320708, 6
24
+ Geohash.encode 47.6062095, -122.3320708, 6
27
25
  #=> "c23nb6"
28
26
  ```
29
27
 
30
28
  ### Decode from geohash
31
29
 
32
30
  ```ruby
33
- GeoHash.decode 'c23nb6'
31
+ Geohash.decode 'c23nb6'
34
32
  #=> [[47.603759765625, -122.332763671875], [47.6092529296875, -122.32177734375]]
35
33
  ```
36
34
 
37
- ### Adjacents
35
+ ### Adjacent
38
36
 
39
37
  ```ruby
40
- GeoHash.adjacent 'c23nb6', :top
38
+ Geohash.adjacent 'c23nb6', :top
41
39
  #=> "c23nb7"
42
40
  ```
43
41
 
44
42
  ### Neighbors
45
43
 
46
44
  ```ruby
47
- GeoHash.neighbors 'xn774c'
45
+ Geohash.neighbors 'xn774c'
48
46
  #=> ["xn774f", "xn7754", "xn7751", "xn7750", "xn774b", "xn7748", "xn7749", "xn774d"]
49
47
 
50
48
  =begin
@@ -61,7 +59,7 @@ GeoHash.neighbors 'xn774c'
61
59
  ### Walk
62
60
 
63
61
  ```ruby
64
- GeoHash.walk 'xn774c', [
62
+ Geohash.walk 'xn774c', [
65
63
  :top,
66
64
  :right,
67
65
  :bottom, :bottom,
data/geohash_ruby.gemspec CHANGED
@@ -5,11 +5,11 @@ require 'geohash_ruby'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'geohash_ruby'
8
- spec.version = GeoHash::VERSION
8
+ spec.version = Geohash::VERSION
9
9
  spec.authors = ['Yuki Iwanaga']
10
10
  spec.email = ['yuki@creasty.com']
11
- spec.summary = 'GeoHash en/decode library written in ruby'
12
- spec.description = 'GeoHash en/decode library written in ruby'
11
+ spec.summary = 'Geohash en/decode library written in ruby'
12
+ spec.description = 'Geohash en/decode library written in ruby'
13
13
  spec.homepage = 'https://github.com/creasty/geohash_ruby'
14
14
  spec.license = 'MIT'
15
15
 
data/lib/geohash_ruby.rb CHANGED
@@ -1,33 +1,33 @@
1
- module GeoHash
1
+ module Geohash
2
2
 
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
 
5
5
  BASE32 = '0123456789bcdefghjkmnpqrstuvwxyz'
6
6
 
7
7
  NEIGHBORS = {
8
- right: {
9
- even: 'bc01fg45238967deuvhjyznpkmstqrwx',
10
- odd: 'p0r21436x8zb9dcf5h7kjnmqesgutwvy',
11
- },
12
- left: {
13
- even: '238967debc01fg45kmstqrwxuvhjyznp',
14
- odd: '14365h7k9dcfesgujnmqp0r2twvyx8zb',
15
- },
16
- top: {
17
- even: 'p0r21436x8zb9dcf5h7kjnmqesgutwvy',
18
- odd: 'bc01fg45238967deuvhjyznpkmstqrwx',
19
- },
20
- bottom: {
21
- even: '14365h7k9dcfesgujnmqp0r2twvyx8zb',
22
- odd: '238967debc01fg45kmstqrwxuvhjyznp',
23
- }
8
+ right: [
9
+ 'bc01fg45238967deuvhjyznpkmstqrwx',
10
+ 'p0r21436x8zb9dcf5h7kjnmqesgutwvy',
11
+ ],
12
+ left: [
13
+ '238967debc01fg45kmstqrwxuvhjyznp',
14
+ '14365h7k9dcfesgujnmqp0r2twvyx8zb',
15
+ ],
16
+ top: [
17
+ 'p0r21436x8zb9dcf5h7kjnmqesgutwvy',
18
+ 'bc01fg45238967deuvhjyznpkmstqrwx',
19
+ ],
20
+ bottom: [
21
+ '14365h7k9dcfesgujnmqp0r2twvyx8zb',
22
+ '238967debc01fg45kmstqrwxuvhjyznp',
23
+ ]
24
24
  }
25
25
 
26
26
  BORDERS = {
27
- right: { even: 'bcfguvyz', odd: 'prxz' },
28
- left: { even: '0145hjnp', odd: '028b' },
29
- top: { even: 'prxz', odd: 'bcfguvyz' },
30
- bottom: { even: '028b', odd: '0145hjnp' },
27
+ right: ['bcfguvyz', 'prxz'],
28
+ left: ['0145hjnp', '028b'],
29
+ top: ['prxz', 'bcfguvyz'],
30
+ bottom: ['028b', '0145hjnp'],
31
31
  }
32
32
 
33
33
  @@neighbors_cache = {}
@@ -79,7 +79,7 @@ module_function
79
79
  mids = [latitude, longitude]
80
80
  bounds = [[-90.0, +90.0], [-180.0, +180.0]]
81
81
 
82
- geohash = []
82
+ geohash = ''
83
83
 
84
84
  precision.times do |i|
85
85
  d = 0
@@ -95,7 +95,7 @@ module_function
95
95
  geohash << BASE32[d]
96
96
  end
97
97
 
98
- geohash.join
98
+ geohash
99
99
  end
100
100
 
101
101
  ###
@@ -137,15 +137,12 @@ module_function
137
137
  return @@adjacent_cache[dir][geohash] if @@adjacent_cache[dir][geohash]
138
138
 
139
139
  head, last = geohash[0..-2], geohash[-1]
140
- type = [:even, :odd][geohash.length % 2]
140
+ parity = geohash.length & 1
141
141
 
142
- head = adjacent(head, dir) if BORDERS[dir][type].include?(last)
142
+ head = adjacent(head, dir) if BORDERS[dir][parity].include?(last)
143
143
 
144
- # NOTICE:
145
- # do not use append `<<` instead of `+`
146
- # head possibly be cached so that mustn't be mutated,
147
- # just create new String instance with it
148
- head = head + BASE32[NEIGHBORS[dir][type].index(last)]
144
+ # NOTICE: do not use append `<<` instead of `+=`
145
+ head += BASE32[NEIGHBORS[dir][parity].index(last)]
149
146
 
150
147
  @@adjacent_cache[dir][geohash] = head
151
148
  end
@@ -159,15 +156,7 @@ module_function
159
156
  # @return {[String]} result geohashes of the walk
160
157
  ###
161
158
  def walk(base, path)
162
- hashes = []
163
-
164
- h = base
165
-
166
- path.each do |dir|
167
- hashes << (h = adjacent(h, dir))
168
- end
169
-
170
- hashes
159
+ path.map { |dir| base = adjacent(base, dir) }
171
160
  end
172
161
 
173
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geohash_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.3'
41
- description: GeoHash en/decode library written in ruby
41
+ description: Geohash en/decode library written in ruby
42
42
  email:
43
43
  - yuki@creasty.com
44
44
  executables: []
@@ -75,5 +75,5 @@ rubyforge_project:
75
75
  rubygems_version: 2.2.2
76
76
  signing_key:
77
77
  specification_version: 4
78
- summary: GeoHash en/decode library written in ruby
78
+ summary: Geohash en/decode library written in ruby
79
79
  test_files: []