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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8001f29fdde201d6e11ae1f5a9d8fa2181e4d56d
4
- data.tar.gz: 80fc06570d990b3c446c1a15abc6ac22caa17eb4
3
+ metadata.gz: 002eef961146be495393e453c8d998205143d45b
4
+ data.tar.gz: ae36f10e19e4a8fe60b62f385361ff5b99159aeb
5
5
  SHA512:
6
- metadata.gz: 3bbbab913d224a405bd2b3c4d1d22650286f7badd06d3ea861544199b375f3bab286a72cc05dc68b9b21bb3acabfc3b0974a78ef1e3dd25cafe7421c8643b3f6
7
- data.tar.gz: 0dd4deec02fbea9b10f2a7a23a52006cfd67ec367e62180f6a35b57715284c3b76432699fac5c92e69d8ec76c0bd122e211a339387d17d90de0b2b6e18b0e379
6
+ metadata.gz: d066823495b8eb875a6c25ef1e9772e24c53e613aba9bbda22e3233ed97061ab5d11c8fbc8b5670b0b54d59b219dd8da72b4b1d6835b2c9f2ec9c31305fc3fac
7
+ data.tar.gz: e102fd689a3e008d7c50a201a5529100bf738aadf882413f22c61fd9e39ba87dd9500279da9b934a804608277deb532c2cbac7dcb86ea68f29fe140bafd1ecde
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+
4
+ # 0.2.2
5
+ * Multiple Google domain suffixes can be parsed
6
+
7
+
8
+ # 0.2.1
9
+ * Added documentation
10
+
11
+
3
12
  # 0.2.0
4
13
  * Can parse place urls
5
14
 
data/README.md CHANGED
@@ -1,2 +1,52 @@
1
- # georama [![Circle CI](https://circleci.com/gh/glasnoster/georama/tree/master.svg?style=svg)](https://circleci.com/gh/glasnoster/georama/tree/master)
2
- A simple google maps url parser
1
+ # georama [![Circle CI](https://circleci.com/gh/glasnoster/georama/tree/master.svg?style=svg)](https://circleci.com/gh/glasnoster/georama/tree/master) [![Gem Version](https://badge.fury.io/rb/georama.svg)](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
+
@@ -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
- is_google = parsed.host == "www.google.com"
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)
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Georama
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -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
 
@@ -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.0
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: 2015-12-06 00:00:00.000000000 Z
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.4.5.1
121
+ rubygems_version: 2.6.10
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: A simple google maps url parser