georama 0.2.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +52 -2
- data/lib/georama/parser.rb +8 -2
- data/lib/georama/url.rb +1 -0
- data/lib/georama/version.rb +1 -1
- data/spec/georama/parser_spec.rb +1 -1
- data/spec/georama/url_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 002eef961146be495393e453c8d998205143d45b
|
4
|
+
data.tar.gz: ae36f10e19e4a8fe60b62f385361ff5b99159aeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d066823495b8eb875a6c25ef1e9772e24c53e613aba9bbda22e3233ed97061ab5d11c8fbc8b5670b0b54d59b219dd8da72b4b1d6835b2c9f2ec9c31305fc3fac
|
7
|
+
data.tar.gz: e102fd689a3e008d7c50a201a5529100bf738aadf882413f22c61fd9e39ba87dd9500279da9b934a804608277deb532c2cbac7dcb86ea68f29fe140bafd1ecde
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,2 +1,52 @@
|
|
1
|
-
# georama [](https://circleci.com/gh/glasnoster/georama/tree/master)
|
2
|
-
|
1
|
+
# georama [](https://circleci.com/gh/glasnoster/georama/tree/master) [](https://badge.fury.io/rb/georama)
|
2
|
+
|
3
|
+
|
4
|
+
A simple google maps url parser
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Simply add the following line to your `Gemfile`:
|
9
|
+
```ruby
|
10
|
+
gem 'georama'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Parsing a general maps url:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
url = "https://www.google.com/maps/@-33.9218305,18.4296954,15z?hl=en"
|
19
|
+
map_url = Georama::Url.new(url)
|
20
|
+
|
21
|
+
map_url.coordinates
|
22
|
+
# => {latitude: -33.9218305, longitude: 18.4296954}
|
23
|
+
|
24
|
+
map_url.latitude
|
25
|
+
# => -33.9218305
|
26
|
+
|
27
|
+
map_url.matadata
|
28
|
+
# => {zoom: 15}
|
29
|
+
|
30
|
+
map_url.zoom
|
31
|
+
# => 15
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
### Parsing a place url:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
url = "https://www.google.com/maps/place/Cape+Town/@-33.9218305,18.4296954,15z/data=foobar"
|
39
|
+
map_url = Georama::Url.new(url)
|
40
|
+
|
41
|
+
map_url.coordinates
|
42
|
+
# => {latitude: -33.9218305, longitude: 18.4296954}
|
43
|
+
|
44
|
+
map_url.place
|
45
|
+
# => "Cape Town"
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
## TODO:
|
50
|
+
|
51
|
+
* Parse directions urls
|
52
|
+
|
data/lib/georama/parser.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module Georama
|
2
2
|
class Parser
|
3
3
|
|
4
|
+
def self.is_valid_url?(url)
|
5
|
+
parsed = URI.parse(url)
|
6
|
+
!parsed.host.nil?
|
7
|
+
end
|
8
|
+
|
4
9
|
def self.is_google_maps_url?(url)
|
5
10
|
raise ArgumentError, "No url specified" if url.nil?
|
6
11
|
parsed = URI.parse(url)
|
7
|
-
|
12
|
+
is_www = parsed.host.split('.')[-3] == 'www'
|
13
|
+
is_google = parsed.host.split('.')[-2] == "google"
|
8
14
|
is_maps = parsed.path.start_with?("/maps/")
|
9
|
-
is_google && is_maps
|
15
|
+
is_www && is_google && is_maps
|
10
16
|
end
|
11
17
|
|
12
18
|
def self.url_type(path)
|
data/lib/georama/url.rb
CHANGED
@@ -4,6 +4,7 @@ module Georama
|
|
4
4
|
|
5
5
|
def initialize(url)
|
6
6
|
raise ArgumentError, "Expected a valid maps url, got nil" if url.nil?
|
7
|
+
raise ArgumentError, "Not a valid url" unless Georama::Parser.is_valid_url?(url)
|
7
8
|
raise ArgumentError, "Not a valid maps url" unless Georama::Parser.is_google_maps_url?(url)
|
8
9
|
@url_string = url
|
9
10
|
@parsed_url = URI.parse(url)
|
data/lib/georama/version.rb
CHANGED
data/spec/georama/parser_spec.rb
CHANGED
@@ -37,7 +37,7 @@ describe Georama::Parser do
|
|
37
37
|
|
38
38
|
context "with an invalid url" do
|
39
39
|
it "returns false" do
|
40
|
-
expect(Georama::Parser.is_google_maps_url?("www.fake.com/foo/bar")).to be_falsey
|
40
|
+
expect(Georama::Parser.is_google_maps_url?("http://www.fake.com/foo/bar")).to be_falsey
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
data/spec/georama/url_spec.rb
CHANGED
@@ -10,6 +10,14 @@ describe Georama::Url do
|
|
10
10
|
context "with an invalid url" do
|
11
11
|
let(:url) { "foo" }
|
12
12
|
|
13
|
+
it "raises an error" do
|
14
|
+
expect { Georama::Url.new(url) }.to raise_error ArgumentError, "Not a valid url"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with an invalid maps url" do
|
19
|
+
let(:url) { "http://www.foo.bar" }
|
20
|
+
|
13
21
|
it "raises an error" do
|
14
22
|
expect { Georama::Url.new(url) }.to raise_error ArgumentError, "Not a valid maps url"
|
15
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: georama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Pretorius
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semvergen
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.10
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: A simple google maps url parser
|