pinpoint 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,10 @@
1
1
  require 'pinpoint/formatter'
2
+ require 'pinpoint/mapable'
2
3
 
3
4
  module Pinpoint
4
5
  class Address
6
+ include Mapable
7
+
5
8
  ATTRIBUTE_NAMES = [
6
9
  :name,
7
10
  :street_and_premises,
@@ -0,0 +1,56 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'pinpoint/mapable_services/google_maps'
3
+ require 'pinpoint/mapable_services/yahoo_maps'
4
+ require 'pinpoint/mapable_services/mapquest'
5
+
6
+ module Pinpoint
7
+ module Mapable
8
+
9
+ ##
10
+ # Public: Creates a URL which can be used to locate the Mapable on a map
11
+ # using one of the supported services:
12
+ #
13
+ # * Google Maps
14
+ # * Yahoo Maps
15
+ # * Mapquest
16
+ #
17
+ # options - A Hash of options which will apply to the map URL
18
+ #
19
+ # :via - A Symbol representing the service to use to create the
20
+ # map URL. Options include:
21
+ #
22
+ # * :google_maps
23
+ # * :yahoo_maps
24
+ # * :mapquest
25
+ #
26
+ # (defaults to google_maps)
27
+ #
28
+ # Returns a String representing the URL which will display the location in
29
+ # the browser.
30
+ #
31
+ def map_url(options = {})
32
+ service = options.fetch(:via, :google_maps)
33
+ service_class = service_class_for(service)
34
+
35
+ service_class.map_url location: self.to_s,
36
+ location_name: self.name
37
+ end
38
+
39
+ private
40
+
41
+ ##
42
+ # Private: Finds the class name of the service that will be used to resolve
43
+ # the map URL in #map_url.
44
+ #
45
+ # service - A Symbol or String representing the service to be looked up
46
+ #
47
+ # Example
48
+ #
49
+ # service_class_for :google_maps
50
+ # # => <Class Pinpoint::MapableService::GoogleMaps>
51
+ #
52
+ def service_class_for(service)
53
+ "Pinpoint::MapableService::#{service.to_s.camelize}".constantize
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,37 @@
1
+ require 'cgi'
2
+
3
+ module Pinpoint
4
+ module MapableService
5
+ class GoogleMaps
6
+
7
+ ##
8
+ # Private: Renders a URL for a given location and location name using the
9
+ # Google Maps mapping service.
10
+ #
11
+ # The location and location name will be properly escaped.
12
+ #
13
+ # options - A Hash of options used in the method
14
+ #
15
+ # :location - A String representing the location to display
16
+ # via the map URL
17
+ # :location_name - A String representing the name of the
18
+ # location to be displayed via the map URL
19
+ #
20
+ # Example
21
+ #
22
+ # map_url location: 'London, UK',
23
+ # location_name: 'Capital of the UK'
24
+ # # => http://maps.google.com?q=London%2C+UK+%28Capital+of+the+UK%29
25
+ #
26
+ def self.map_url(options = {})
27
+ escaped_map_location = CGI.escape options.fetch(:location).to_str
28
+ escaped_location_name = CGI.escape "(#{options.fetch(:location_name)})"
29
+
30
+ 'http://maps.google.com?q=' +
31
+ escaped_map_location +
32
+ '+' +
33
+ escaped_location_name
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require 'cgi'
2
+
3
+ module Pinpoint
4
+ module MapableService
5
+ class Mapquest
6
+
7
+ ##
8
+ # Private: Renders a URL for a given location and location name using the
9
+ # Mapquest mapping service.
10
+ #
11
+ # The location and location name will be properly escaped.
12
+ #
13
+ # options - A Hash of options used in the method
14
+ #
15
+ # :location - A String representing the location to display
16
+ # via the map URL
17
+ # :location_name - A String representing the name of the
18
+ # location to be displayed via the map URL
19
+ #
20
+ # Example
21
+ #
22
+ # map_url location: 'London, UK',
23
+ # location_name: 'Capital of the UK'
24
+ # # => http://mapquest.com?q=London%2C+UK+%28Capital+of+the+UK%29
25
+ #
26
+ def self.map_url(options = {})
27
+ escaped_map_location = CGI.escape options.fetch(:location).to_str
28
+ escaped_location_name = CGI.escape "(#{options.fetch(:location_name)})"
29
+
30
+ 'http://mapquest.com?q=' +
31
+ escaped_map_location +
32
+ '+' +
33
+ escaped_location_name
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require 'cgi'
2
+
3
+ module Pinpoint
4
+ module MapableService
5
+ class YahooMaps
6
+
7
+ ##
8
+ # Private: Renders a URL for a given location and location name using the
9
+ # Yahoo Maps mapping service.
10
+ #
11
+ # The location and location name will be properly escaped.
12
+ #
13
+ # options - A Hash of options used in the method
14
+ #
15
+ # :location - A String representing the location to display
16
+ # via the map URL
17
+ # :location_name - A String representing the name of the
18
+ # location to be displayed via the map URL
19
+ #
20
+ # Example
21
+ #
22
+ # map_url location: 'London, UK',
23
+ # location_name: 'Capital of the UK'
24
+ # # => http://maps.yahoo.com#q=London%2C+UK&tt=Capital+of+the+UK
25
+ #
26
+ def self.map_url(options = {})
27
+ escaped_map_location = CGI.escape options.fetch(:location).to_str
28
+ escaped_location_name = CGI.escape options.fetch(:location_name)
29
+
30
+ 'http://maps.yahoo.com#q=' +
31
+ escaped_map_location +
32
+ '&tt=' +
33
+ escaped_location_name
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Pinpoint
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,17 @@
1
+ require 'rspectacular'
2
+ require 'pinpoint/mapable_services/google_maps'
3
+
4
+ describe Pinpoint::MapableService::GoogleMaps do
5
+ it 'can create a GoogleMaps URL from the location string' do
6
+ map_url = Pinpoint::MapableService::GoogleMaps.map_url(
7
+ location_name: 'name with \\stuff/',
8
+ location: 'location with \\stuff/')
9
+
10
+ map_url.should eql(
11
+ 'http://maps.google.com?q=' +
12
+ 'location+with+%5Cstuff%2F' +
13
+ '+' +
14
+ '%28name+with+%5Cstuff%2F%29'
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspectacular'
2
+ require 'pinpoint/mapable_services/mapquest'
3
+
4
+ describe Pinpoint::MapableService::Mapquest do
5
+ it 'can create a Mapquest URL from the location string' do
6
+ map_url = Pinpoint::MapableService::Mapquest.map_url(
7
+ location_name: 'name with \\stuff/',
8
+ location: 'location with \\stuff/')
9
+
10
+ map_url.should eql(
11
+ 'http://mapquest.com?q=' +
12
+ 'location+with+%5Cstuff%2F' +
13
+ '+' +
14
+ '%28name+with+%5Cstuff%2F%29'
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspectacular'
2
+ require 'pinpoint/mapable_services/yahoo_maps'
3
+
4
+ describe Pinpoint::MapableService::YahooMaps do
5
+ it 'can create a YahooMaps URL from the location string' do
6
+ map_url = Pinpoint::MapableService::YahooMaps.map_url(
7
+ location_name: 'name with \\stuff/',
8
+ location: 'location with \\stuff/')
9
+
10
+ map_url.should eql(
11
+ 'http://maps.yahoo.com#q=' +
12
+ 'location+with+%5Cstuff%2F' +
13
+ '&tt=' +
14
+ 'name+with+%5Cstuff%2F'
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspectacular'
2
+ require 'pinpoint/mapable'
3
+
4
+ class MyMapableClass
5
+ include Pinpoint::Mapable
6
+ end
7
+
8
+ describe Pinpoint::Mapable do
9
+ let(:mapable) { MyMapableClass.new }
10
+
11
+ it 'can locate the map URL for itself via a given service' do
12
+ Pinpoint::MapableService::GoogleMaps.should_receive(:map_url)
13
+ .with(location_name: 'my_name',
14
+ location: 'my_location')
15
+ .and_return('map_url')
16
+
17
+ mapable.should_receive(:to_s).and_return 'my_location'
18
+ mapable.should_receive(:name).and_return 'my_name'
19
+
20
+ mapable.map_url(:via => :google_maps)
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -100,6 +100,10 @@ files:
100
100
  - lib/pinpoint/format/tokenizer.rb
101
101
  - lib/pinpoint/format.rb
102
102
  - lib/pinpoint/formatter.rb
103
+ - lib/pinpoint/mapable.rb
104
+ - lib/pinpoint/mapable_services/google_maps.rb
105
+ - lib/pinpoint/mapable_services/mapquest.rb
106
+ - lib/pinpoint/mapable_services/yahoo_maps.rb
103
107
  - lib/pinpoint/model_support.rb
104
108
  - lib/pinpoint/validations.rb
105
109
  - lib/pinpoint/version.rb
@@ -117,6 +121,10 @@ files:
117
121
  - spec/format/tokenizer_spec.rb
118
122
  - spec/format_spec.rb
119
123
  - spec/formatter_spec.rb
124
+ - spec/mapable_services/google_maps_spec.rb
125
+ - spec/mapable_services/mapquest_spec.rb
126
+ - spec/mapable_services/yahoo_maps_spec.rb
127
+ - spec/mapable_spec.rb
120
128
  - spec/model_support_spec.rb
121
129
  - spec/spec_helper.rb
122
130
  - spec/support/focused.rb
@@ -158,6 +166,10 @@ test_files:
158
166
  - spec/format/tokenizer_spec.rb
159
167
  - spec/format_spec.rb
160
168
  - spec/formatter_spec.rb
169
+ - spec/mapable_services/google_maps_spec.rb
170
+ - spec/mapable_services/mapquest_spec.rb
171
+ - spec/mapable_services/yahoo_maps_spec.rb
172
+ - spec/mapable_spec.rb
161
173
  - spec/model_support_spec.rb
162
174
  - spec/spec_helper.rb
163
175
  - spec/support/focused.rb