google_maps_geocoder 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,5 +1,3 @@
1
1
  lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
2
  LICENSE.txt
3
+ README.md
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .DS_Store
3
+ coverage
4
+ doc
5
+ Gemfile.lock
6
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - 1.9.3
6
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,10 +1,2 @@
1
- source "http://rubygems.org"
2
-
3
- gem 'activesupport'
4
- gem 'rack'
5
-
6
- group :development do
7
- gem 'jeweler'
8
- gem 'rcov'
9
- gem 'rspec'
10
- end
1
+ source 'http://rubygems.org'
2
+ gemspec
@@ -1,38 +1,58 @@
1
- = google_maps_geocoder
1
+ # GoogleMapsGeocoder [![Build Status](https://secure.travis-ci.org/ivanoblomov/google_maps_geocoder.png)](http://travis-ci.org/ivanoblomov/google_maps_geocoder)
2
2
 
3
3
  A simple PORO wrapper for geocoding with Google Maps.
4
4
 
5
- chez_barack = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
5
+ ## Initialize in One Step
6
6
 
7
+ ```ruby
8
+ chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania Washington'
9
+ ```
10
+
11
+ ## Examples
12
+
13
+ Get the complete, formatted address:
14
+
15
+ ```ruby
7
16
  chez_barack.formatted_address
8
- => "1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA"
17
+ ```
18
+
19
+ ...standardized name of the city:
9
20
 
21
+ ```ruby
10
22
  chez_barack.city
11
- => "Washington D.C."
23
+ ```
12
24
 
25
+ ...full name of the state or region:
26
+
27
+ ```ruby
13
28
  chez_barack.state_long_name
14
- => "District of Columbia"
29
+ ```
30
+
31
+ ...standard abbreviation for the state/region:
15
32
 
33
+ ```ruby
16
34
  chez_barack.state_short_name
17
- => "DC"
35
+ ```
36
+
37
+ ## API
18
38
 
19
39
  The complete, hopefully self-explanatory, API is:
20
40
 
21
- city
22
- country_long_name
23
- country_short_name
24
- county
25
- exact_match?
26
- formatted_address
27
- formatted_street_address
28
- lat
29
- lng
30
- partial_match?
31
- postal_code
32
- state_long_name
33
- state_short_name
34
-
35
- == Contributing to google_maps_geocoder
41
+ * city
42
+ * country_long_name
43
+ * country_short_name
44
+ * county
45
+ * exact_match?
46
+ * formatted_address
47
+ * formatted_street_address
48
+ * lat
49
+ * lng
50
+ * partial_match?
51
+ * postal_code
52
+ * state_long_name
53
+ * state_short_name
54
+
55
+ ## Contributing to google_maps_geocoder
36
56
 
37
57
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
38
58
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -42,6 +62,6 @@ state_short_name
42
62
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
43
63
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
44
64
 
45
- == Copyright
65
+ ## Copyright
46
66
 
47
- Copyright (c) 2011 Roderick Monje. See LICENSE.txt for further details.
67
+ Copyright (c) 2011 Roderick Monje. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,53 +1,10 @@
1
- require 'rubygems'
2
1
  require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "google_maps_geocoder"
16
- gem.homepage = "http://github.com/ivanoblomov/google_maps_geocoder"
17
- gem.license = "MIT"
18
- gem.summary = %Q{A simple PORO wrapper for geocoding with Google Maps.}
19
- gem.description = %Q{Geocode a location without worrying about parsing Google Maps' response. GoogleMapsGeocoder wraps it in a plain-old Ruby object.}
20
- gem.email = "rod@seologic.com"
21
- gem.authors = ["Roderick Monje"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
35
4
 
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
5
+ RSpec::Core::RakeTask.new(:test) do |t|
6
+ t.pattern = 'spec/*/*_spec.rb'
7
+ t.verbose = false
41
8
  end
42
9
 
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "google_maps_geocoder #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
10
+ task :default => :test
@@ -1,61 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ require File.expand_path('../lib/version', __FILE__)
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "google_maps_geocoder"
8
- s.version = "0.2.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Roderick Monje"]
12
- s.date = "2012-09-19"
5
+ s.version = GoogleMapsGeocoder::VERSION.dup
6
+ s.summary = "A simple PORO wrapper for geocoding with Google Maps."
13
7
  s.description = "Geocode a location without worrying about parsing Google Maps' response. GoogleMapsGeocoder wraps it in a plain-old Ruby object."
14
- s.email = "rod@seologic.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "LICENSE.txt",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "google_maps_geocoder.gemspec",
27
- "lib/google_maps_geocoder.rb",
28
- "spec/lib/google_maps_geocoder_spec.rb",
29
- "spec/spec_helper.rb"
30
- ]
31
8
  s.homepage = "http://github.com/ivanoblomov/google_maps_geocoder"
32
- s.licenses = ["MIT"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = "1.8.11"
35
- s.summary = "A simple PORO wrapper for geocoding with Google Maps."
9
+ s.authors = ["Roderick Monje"]
36
10
 
37
- if s.respond_to? :specification_version then
38
- s.specification_version = 3
11
+ s.add_development_dependency 'rake', '>= 0'
12
+ s.add_development_dependency 'rspec', '>= 0'
13
+ s.add_development_dependency 'simplecov', '>= 0'
39
14
 
40
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
42
- s.add_runtime_dependency(%q<rack>, [">= 0"])
43
- s.add_development_dependency(%q<jeweler>, [">= 0"])
44
- s.add_development_dependency(%q<rcov>, [">= 0"])
45
- s.add_development_dependency(%q<rspec>, [">= 0"])
46
- else
47
- s.add_dependency(%q<activesupport>, [">= 0"])
48
- s.add_dependency(%q<rack>, [">= 0"])
49
- s.add_dependency(%q<jeweler>, [">= 0"])
50
- s.add_dependency(%q<rcov>, [">= 0"])
51
- s.add_dependency(%q<rspec>, [">= 0"])
52
- end
53
- else
54
- s.add_dependency(%q<activesupport>, [">= 0"])
55
- s.add_dependency(%q<rack>, [">= 0"])
56
- s.add_dependency(%q<jeweler>, [">= 0"])
57
- s.add_dependency(%q<rcov>, [">= 0"])
58
- s.add_dependency(%q<rspec>, [">= 0"])
59
- end
60
- end
15
+ s.add_runtime_dependency 'activesupport', '>= 0'
16
+ s.add_runtime_dependency 'rack', '>= 0'
61
17
 
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
21
+ s.require_paths = ["lib"]
22
+ end
@@ -17,27 +17,27 @@ class GoogleMapsGeocoder
17
17
  #
18
18
  # ==== Attributes
19
19
  #
20
- # * +address+ - a geocodable address
20
+ # * +data+ - a geocodable address
21
21
  #
22
22
  # ==== Examples
23
23
  #
24
24
  # white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
25
25
  # white_house.formatted_address
26
- # => "1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA"
26
+ # => "1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 20500, USA"
27
27
  def initialize data
28
28
  if data.is_a? String
29
29
  response = Net::HTTP.get_response(URI.parse("http://maps.googleapis.com/maps/api/geocode/json?address=#{Rack::Utils.escape(data)}&sensor=false"))
30
30
  @json = ActiveSupport::JSON.decode(response.body)
31
- raise "Geocoding \"#{address}\" exceeded query limit! Google returned...\n#{@json.inspect}" if @json.blank? || @json['status'] != 'OK'
31
+ raise "Geocoding \"#{data}\" exceeded query limit! Google returned...\n#{@json.inspect}" if @json.blank? || @json['status'] != 'OK'
32
32
  else
33
33
  @json = data
34
34
  address = data['formatted_address']
35
35
  end
36
36
 
37
- logger = Logger.new(STDERR)
38
- logger.info('GoogleMapsGeocoder') { "Geocoded \"#{address}\" and Google returned...\n#{@json.inspect}" }
39
-
40
37
  @city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
38
+
39
+ logger = Logger.new(STDERR)
40
+ logger.info('GoogleMapsGeocoder') { "Geocoded \"#{data}\" => \"#{self.formatted_address}\"" }
41
41
  end
42
42
 
43
43
  # Instance Methods ===============================================================================
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ class GoogleMapsGeocoder
2
+ VERSION = '0.3.0'.freeze unless defined?(GoogleMapsGeocoder::VERSION)
3
+ end
@@ -3,10 +3,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe GoogleMapsGeocoder do
4
4
  before(:all) do
5
5
  begin
6
- @exact_match = GoogleMapsGeocoder.new('837 Union St Brooklyn NY')
6
+ @exact_match = GoogleMapsGeocoder.new('837 Union Street Brooklyn NY')
7
7
  @partial_match = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
8
8
  rescue SocketError
9
- @no_network = true
9
+ @no_network = true
10
10
  rescue RuntimeError
11
11
  @query_limit = true
12
12
  end
@@ -14,15 +14,15 @@ describe GoogleMapsGeocoder do
14
14
 
15
15
  before(:each) do
16
16
  pending 'waiting for a network connection', :if => @no_network
17
- pending 'waiting for query limit to pass', :if => @query_limit
17
+ pending 'waiting for query limit to pass', :if => @query_limit
18
18
  end
19
19
 
20
- context 'with "837 Union St Brooklyn NY"' do
20
+ context 'with "837 Union Street Brooklyn NY"' do
21
21
  subject { @exact_match }
22
22
  specify { should be_exact_match }
23
23
 
24
24
  context 'address' do
25
- specify { subject.formatted_street_address.should == '837 Union St' }
25
+ specify { subject.formatted_street_address.should == '837 Union Street' }
26
26
  specify { subject.city.should == 'Brooklyn' }
27
27
  specify { subject.county.should == 'Kings' }
28
28
  specify { subject.state_long_name.should == 'New York' }
@@ -30,7 +30,7 @@ describe GoogleMapsGeocoder do
30
30
  specify { subject.postal_code.should =~ /1121[0-9]/ }
31
31
  specify { subject.country_short_name.should == 'US' }
32
32
  specify { subject.country_long_name.should == 'United States' }
33
- specify { subject.formatted_address.should =~ /837 Union St, Brooklyn, NY 1121[0-9], USA/ }
33
+ specify { subject.formatted_address.should =~ /837 Union Street, Brooklyn, NY 1121[0-9], USA/ }
34
34
  end
35
35
 
36
36
  context 'coordinates' do
@@ -44,14 +44,14 @@ describe GoogleMapsGeocoder do
44
44
  specify { should be_partial_match }
45
45
 
46
46
  context 'address' do
47
- specify { subject.formatted_street_address.should == '1600 Pennsylvania Ave NW' }
47
+ specify { subject.formatted_street_address.should == '1600 Pennsylvania Avenue Northwest' }
48
48
  specify { subject.city.should == 'Washington' }
49
49
  specify { subject.state_long_name.should == 'District of Columbia' }
50
50
  specify { subject.state_short_name.should == 'DC' }
51
51
  specify { subject.postal_code.should =~ /2050[0-9]/ }
52
52
  specify { subject.country_short_name.should == 'US' }
53
53
  specify { subject.country_long_name.should == 'United States' }
54
- specify { subject.formatted_address.should =~ /1600 Pennsylvania Ave NW, Washington, DC 2050[0-9], USA/ }
54
+ specify { subject.formatted_address.should =~ /1600 Pennsylvania Avenue Northwest, President's Park, Washington, DC 2050[0-9], USA/ }
55
55
  end
56
56
 
57
57
  context 'coordinates' do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rubygems'
2
5
  require 'bundler'
3
6
  begin
metadata CHANGED
@@ -1,145 +1,140 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: google_maps_geocoder
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Roderick Monje
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-19 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rack
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
- type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: jeweler
50
- prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
52
33
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
60
38
  type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: rcov
64
39
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
66
49
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
74
54
  type: :development
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: rspec
78
55
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
80
57
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
88
- type: :development
89
- version_requirements: *id005
90
- description: Geocode a location without worrying about parsing Google Maps' response. GoogleMapsGeocoder wraps it in a plain-old Ruby object.
91
- email: rod@seologic.com
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rack
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Geocode a location without worrying about parsing Google Maps' response.
95
+ GoogleMapsGeocoder wraps it in a plain-old Ruby object.
96
+ email:
92
97
  executables: []
93
-
94
98
  extensions: []
95
-
96
- extra_rdoc_files:
97
- - LICENSE.txt
98
- - README.rdoc
99
- files:
99
+ extra_rdoc_files: []
100
+ files:
100
101
  - .document
102
+ - .gitignore
103
+ - .travis.yml
101
104
  - Gemfile
102
105
  - LICENSE.txt
103
- - README.rdoc
106
+ - README.md
104
107
  - Rakefile
105
- - VERSION
106
108
  - google_maps_geocoder.gemspec
107
109
  - lib/google_maps_geocoder.rb
110
+ - lib/version.rb
108
111
  - spec/lib/google_maps_geocoder_spec.rb
109
112
  - spec/spec_helper.rb
110
113
  homepage: http://github.com/ivanoblomov/google_maps_geocoder
111
- licenses:
112
- - MIT
114
+ licenses: []
113
115
  post_install_message:
114
116
  rdoc_options: []
115
-
116
- require_paths:
117
+ require_paths:
117
118
  - lib
118
- required_ruby_version: !ruby/object:Gem::Requirement
119
+ required_ruby_version: !ruby/object:Gem::Requirement
119
120
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
127
- required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
126
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
136
131
  requirements: []
137
-
138
132
  rubyforge_project:
139
- rubygems_version: 1.8.11
133
+ rubygems_version: 1.8.25
140
134
  signing_key:
141
135
  specification_version: 3
142
136
  summary: A simple PORO wrapper for geocoding with Google Maps.
143
- test_files: []
144
-
137
+ test_files:
138
+ - spec/lib/google_maps_geocoder_spec.rb
139
+ - spec/spec_helper.rb
145
140
  has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0