plus_codes 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1da7f815765ecb2206cb0649c9aa38dd3fa74f02
4
- data.tar.gz: 31e1d4218ecd47d5430e73b47760ae8acda9d163
3
+ metadata.gz: 69d6043d4051f33ae155cb1659af7e8e533054ae
4
+ data.tar.gz: 2eddbf67c2fd1e8ae3b230150868a074d173d41a
5
5
  SHA512:
6
- metadata.gz: dde33abf4454355f14b1497c82266e97c2e8cfe5b7a6cf0a8567f133ed0d5d225c433cd8a87029a5c8aab87f10f524095254b08f00e035f97c4224c4f92bb192
7
- data.tar.gz: 6e01e7ed5b9bfe233a819a6195122e7d5b0af0f7ef53ae3c5f5d962b9d9d8c67e4165c10e1e201a7fdd4cc48851dbc0aa1c057246d3671646d7e93934049f214
6
+ metadata.gz: 3a1d9f99221ae07169b7dcd1145b7a0a2a863636043fa5f6d602abd919c992e614cd9a2c2f332abd7feb5abb2267406816f4632273f6c93948055c3bb76c632c
7
+ data.tar.gz: d81015cd0361126dc140b86590bdd28bee3a6f6f26caff6a78a9ef77154c6ced5ebf5992b2b9366a74be16cf56a638b014daa287524feee91fd7c3c30ff4f752
@@ -25,16 +25,13 @@ module PlusCodes
25
25
  # We can have an even number of padding characters before the separator,
26
26
  # but then it must be the final character.
27
27
  if code.include?(PADDING)
28
- # Not allowed to start with them!
29
28
  return false if code.start_with?(PADDING)
30
-
31
- # There can only be one group and it must have even length.
32
- pad_match = /(#{PADDING}+)/.match(code).to_a
33
- return false if pad_match.length != 2
34
- match = pad_match[1]
35
- return false if match.length.odd? || match.length > SEPARATOR_POSITION - 2
36
-
37
- # If the code is long enough to end with a separator, make sure it does.
29
+ pad_match = code.scan(/#{PADDING}+/)
30
+ return false unless pad_match.one?
31
+ padding = pad_match[0]
32
+ return false if padding.length.odd?
33
+ return false if padding.length > SEPARATOR_POSITION - 2
34
+ return false if code[-2] != PADDING
38
35
  return false if code[-1] != SEPARATOR
39
36
  end
40
37
 
@@ -312,7 +309,7 @@ module PlusCodes
312
309
  lng_place_value = GRID_SIZE_DEGREES
313
310
  (0...code.length).each do |i|
314
311
  code_index = DECODE[code[i].ord]
315
- row = (code_index / GRID_COLUMNS).floor()
312
+ row = (code_index / GRID_COLUMNS).floor
316
313
  col = code_index % GRID_COLUMNS
317
314
 
318
315
  lat_place_value /= GRID_ROWS
@@ -1,3 +1,3 @@
1
1
  module PlusCodes
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -18,7 +18,7 @@ class PlusCodesTest < Test::Unit::TestCase
18
18
  is_valid_olc = @olc.valid?(code)
19
19
  is_short_olc = @olc.short?(code)
20
20
  is_full_olc = @olc.full?(code)
21
- result = is_full == is_full_olc && is_short_olc == is_short && is_valid_olc == is_valid
21
+ result = is_valid_olc == is_valid && is_short_olc == is_short && is_full_olc == is_full
22
22
  assert_true(result)
23
23
  end
24
24
  end
@@ -74,6 +74,10 @@ class PlusCodesTest < Test::Unit::TestCase
74
74
  @olc.recover_nearest('9C3W9QCJ+2VX', 51.3708675, -1.217765625)
75
75
  end
76
76
 
77
+ def test_valid?_with_speacial_case
78
+ assert_false(@olc.valid?('3W00CJJJ+'))
79
+ end
80
+
77
81
  def read_csv_lines(csv_file)
78
82
  f = File.open(File.join(@test_data_folder_path, csv_file), 'r')
79
83
  f.each_line.lazy.select { |line| line !~ /^\s*#/ }.map { |line| line.chop }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plus_codes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei-Ming Wu