georama 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/georama/parser.rb +2 -0
- data/lib/georama/url.rb +7 -0
- data/lib/georama/version.rb +1 -1
- data/spec/georama/parser_spec.rb +17 -1
- data/spec/georama/url_spec.rb +52 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8001f29fdde201d6e11ae1f5a9d8fa2181e4d56d
|
4
|
+
data.tar.gz: 80fc06570d990b3c446c1a15abc6ac22caa17eb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bbbab913d224a405bd2b3c4d1d22650286f7badd06d3ea861544199b375f3bab286a72cc05dc68b9b21bb3acabfc3b0974a78ef1e3dd25cafe7421c8643b3f6
|
7
|
+
data.tar.gz: 0dd4deec02fbea9b10f2a7a23a52006cfd67ec367e62180f6a35b57715284c3b76432699fac5c92e69d8ec76c0bd122e211a339387d17d90de0b2b6e18b0e379
|
data/CHANGELOG.md
CHANGED
data/lib/georama/parser.rb
CHANGED
data/lib/georama/url.rb
CHANGED
@@ -33,12 +33,19 @@ module Georama
|
|
33
33
|
metadata[:zoom]
|
34
34
|
end
|
35
35
|
|
36
|
+
def place
|
37
|
+
return nil unless type == :place
|
38
|
+
@place ||= path_components[2].gsub("+", " ")
|
39
|
+
end
|
40
|
+
|
36
41
|
private
|
37
42
|
|
38
43
|
def coordinates_component
|
39
44
|
@coordinates_component ||= case type
|
40
45
|
when :general
|
41
46
|
path_components[1]
|
47
|
+
when :place
|
48
|
+
path_components[3]
|
42
49
|
end
|
43
50
|
end
|
44
51
|
|
data/lib/georama/version.rb
CHANGED
data/spec/georama/parser_spec.rb
CHANGED
@@ -2,6 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Georama::Parser do
|
4
4
|
|
5
|
+
let(:general_url) { "https://www.google.com/maps/@-33.9218305,18.4296954,15z?hl=en" }
|
6
|
+
|
5
7
|
describe :url_type do
|
6
8
|
|
7
9
|
context "with an no path" do
|
@@ -10,6 +12,20 @@ describe Georama::Parser do
|
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
15
|
+
context "with a general maps path" do
|
16
|
+
let(:path) { "/maps/@-33.9218305,18.4296954,15z?hl=en" }
|
17
|
+
it "returns the correct type" do
|
18
|
+
expect(Georama::Parser.url_type(path)).to eq(:general)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with a place path" do
|
23
|
+
let(:path) { "/maps/place/Cape+Town/@-33.9092719,18.8965703,8.13z/data=foobar" }
|
24
|
+
it "returns the correct type" do
|
25
|
+
expect(Georama::Parser.url_type(path)).to eq(:place)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
end
|
14
30
|
|
15
31
|
describe :is_google_maps_url? do
|
@@ -27,7 +43,7 @@ describe Georama::Parser do
|
|
27
43
|
|
28
44
|
context "with a valid url" do
|
29
45
|
it "returns true" do
|
30
|
-
expect(Georama::Parser.is_google_maps_url?(
|
46
|
+
expect(Georama::Parser.is_google_maps_url?(general_url)).to be_truthy
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|
data/spec/georama/url_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Georama::Url do
|
4
4
|
|
5
5
|
let(:valid_general_url) { "https://www.google.com/maps/@-33.9218305,18.4296954,15z?hl=en" }
|
6
|
+
let(:valid_place_url) { "https://www.google.com/maps/place/Cape+Town/@-33.9218305,18.4296954,15z/data=foobar" }
|
6
7
|
|
7
8
|
describe :initialize do
|
8
9
|
|
@@ -29,27 +30,34 @@ describe Georama::Url do
|
|
29
30
|
end
|
30
31
|
|
31
32
|
describe :type do
|
32
|
-
let(:result) { Georama::Url.new(
|
33
|
+
let(:result) { Georama::Url.new(url) }
|
33
34
|
|
34
35
|
context "with a general url" do
|
35
|
-
|
36
|
+
let(:url) { valid_general_url }
|
36
37
|
it "returns the correct type" do
|
37
38
|
expect(result.type).to eq(:general)
|
38
39
|
end
|
40
|
+
end
|
39
41
|
|
42
|
+
context "with a place url" do
|
43
|
+
let(:url) { valid_place_url }
|
44
|
+
it "returns the correct type" do
|
45
|
+
expect(result.type).to eq(:place)
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
|
43
50
|
describe :coordinates do
|
51
|
+
let(:expected_coordinates) do
|
52
|
+
{
|
53
|
+
latitude: -33.9218305,
|
54
|
+
longitude: 18.4296954
|
55
|
+
}
|
56
|
+
end
|
57
|
+
let(:result) { Georama::Url.new(url) }
|
44
58
|
|
45
59
|
context "with a general url" do
|
46
|
-
let(:
|
47
|
-
let(:expected_coordinates) do
|
48
|
-
{
|
49
|
-
latitude: -33.9218305,
|
50
|
-
longitude: 18.4296954
|
51
|
-
}
|
52
|
-
end
|
60
|
+
let(:url) { valid_general_url }
|
53
61
|
|
54
62
|
it "extracts the coordinates" do
|
55
63
|
expect(result.coordinates).to eq(expected_coordinates)
|
@@ -66,11 +74,20 @@ describe Georama::Url do
|
|
66
74
|
end
|
67
75
|
end
|
68
76
|
|
77
|
+
context "with a place url" do
|
78
|
+
let(:url) { valid_place_url }
|
79
|
+
|
80
|
+
it "extracts the coordinates" do
|
81
|
+
expect(result.coordinates).to eq(expected_coordinates)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
end
|
70
86
|
|
71
87
|
describe :metadata do
|
88
|
+
let(:result) { Georama::Url.new(url) }
|
72
89
|
context "with a general url" do
|
73
|
-
let(:
|
90
|
+
let(:url) { valid_general_url }
|
74
91
|
it "extracts the zoom" do
|
75
92
|
expect(result.metadata[:zoom]).to eq(15)
|
76
93
|
end
|
@@ -82,7 +99,32 @@ describe Georama::Url do
|
|
82
99
|
end
|
83
100
|
end
|
84
101
|
|
102
|
+
context "with a place url" do
|
103
|
+
let(:url) { valid_place_url }
|
104
|
+
it "extracts the zoom" do
|
105
|
+
expect(result.metadata[:zoom]).to eq(15)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe :place do
|
112
|
+
let(:result) { Georama::Url.new(url) }
|
113
|
+
context "with a general url" do
|
114
|
+
let(:url) { valid_general_url }
|
85
115
|
|
116
|
+
it "returns nil" do
|
117
|
+
expect(result.place).to be_nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "with a place url" do
|
122
|
+
let(:url) { valid_place_url }
|
123
|
+
|
124
|
+
it "returns the correct place" do
|
125
|
+
expect(result.place).to eq("Cape Town")
|
126
|
+
end
|
127
|
+
end
|
86
128
|
end
|
87
129
|
|
88
130
|
end
|