cloudmade 0.1.4 → 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.
@@ -0,0 +1 @@
1
+ rvm: 1.9.2
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # CloudMade
2
+ [![Build Status](https://secure.travis-ci.org/klaustopher/cloudmade.png?branch=master)](http://travis-ci.org/klaustopher/cloudmade)
2
3
  ---
3
4
 
4
5
  This is a ruby Gem to use the amazing API for [Cloudmade](http://www.cloudmade.com). They bring you cool services powered by [OpenStreetMaps](http://www.openstreetmaps.org). Check out their website.
@@ -10,7 +11,7 @@ In the future I will update this Gem to use the version v2 of the API. I just :h
10
11
 
11
12
  ## Usage
12
13
  Add the Gem to your Gemfile:
13
- gem 'cloudmade', '0.1.2'
14
+ gem 'cloudmade', '0.1.4'
14
15
 
15
16
  Run the bundle command to update your Gemspec and you're ready to roll
16
17
 
@@ -40,7 +41,7 @@ At the end I will attach the original documentation. Have fun:
40
41
 
41
42
  CloudMadeAPI is a Ruby API for CloudMade's online services: Geocoding, Routing and Tiles.
42
43
 
43
- API documentation is available http://cloudmade.com/developers/docs/
44
+ API documentation is available http://developers.cloudmade.com/projects/show/geocoding-http-api
44
45
 
45
46
  Install
46
47
  =======
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require "bundler/gem_tasks"
3
3
  require 'rake'
4
4
  require 'rake/testtask'
5
5
 
6
+ task :default => [:test_units]
6
7
  task :test => [:test_units]
7
8
 
8
9
  desc "Run unit tests"
@@ -106,7 +106,11 @@ module CloudMade
106
106
  end
107
107
 
108
108
  def to_s
109
- results.join(',') if results != nil
109
+ results.join(',') if results.any?
110
+ end
111
+
112
+ def to_wkt
113
+ results.map { |result| result.to_wkt unless result.geometry.nil? }.compact
110
114
  end
111
115
  end
112
116
 
@@ -140,5 +144,9 @@ module CloudMade
140
144
  def to_s
141
145
  self.geometry.to_s
142
146
  end
147
+
148
+ def to_wkt
149
+ self.geometry.to_wkt
150
+ end
143
151
  end
144
152
  end
@@ -28,6 +28,11 @@ module CloudMade
28
28
  when 'multipolygon' then return MultiPolygon.new(data['coordinates'])
29
29
  end
30
30
  end
31
+
32
+ end
33
+
34
+ def wkt_helper
35
+ raise 'Not implemented'
31
36
  end
32
37
  end
33
38
 
@@ -59,6 +64,14 @@ module CloudMade
59
64
  def to_latlon
60
65
  "#{@lat},#{@lon}"
61
66
  end
67
+
68
+ def to_wkt
69
+ "POINT (#{wkt_helper})"
70
+ end
71
+
72
+ def wkt_helper
73
+ "#{@lat} #{@lon}"
74
+ end
62
75
  end
63
76
 
64
77
  class Line < Geometry
@@ -71,6 +84,14 @@ module CloudMade
71
84
  def to_s
72
85
  "Line(#{@points.join(',')})"
73
86
  end
87
+
88
+ def to_wkt
89
+ "LINESTRING #{wkt_helper}"
90
+ end
91
+
92
+ def wkt_helper
93
+ "(#{@points.map{ |point| point.wkt_helper }.join(', ')})"
94
+ end
74
95
  end
75
96
 
76
97
 
@@ -84,6 +105,14 @@ module CloudMade
84
105
  def to_s
85
106
  "MultiLine(#{@lines.join(',')})"
86
107
  end
108
+
109
+ def to_wkt
110
+ "MULTILINESTRING (#{wkt_helper})"
111
+ end
112
+
113
+ def wkt_helper
114
+ @lines.map(&:wkt_helper).join(', ')
115
+ end
87
116
  end
88
117
 
89
118
  class Polygon < Geometry
@@ -98,6 +127,15 @@ module CloudMade
98
127
  def to_s
99
128
  "Polygon(#{@border_line} - (#{@holes.join(',')}))"
100
129
  end
130
+
131
+ def to_wkt
132
+ "POLYGON (#{wkt_helper})"
133
+ end
134
+
135
+ def wkt_helper
136
+ holes = @holes.map(&:wkt_helper).join(', ') if @holes.any?
137
+ [@border_line.wkt_helper, holes].compact.join(', ')
138
+ end
101
139
  end
102
140
 
103
141
  class MultiPolygon < Geometry
@@ -110,6 +148,14 @@ module CloudMade
110
148
  def to_s
111
149
  "MultiPolygon(#{@polygons.join(',')})"
112
150
  end
151
+
152
+ def to_wkt
153
+ "MULTIPOLYGON (#{wkt_helper})"
154
+ end
155
+
156
+ def wkt_helper
157
+ @polygons.map { |polygon| "(#{polygon.wkt_helper})"}.join(', ')
158
+ end
113
159
  end
114
160
 
115
161
  class BBox < Geometry
@@ -1,3 +1,3 @@
1
1
  module Cloudmade
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -29,6 +29,11 @@ class PointTest < Test::Unit::TestCase #:nodoc: all
29
29
  point = CloudMade::Point.new(1, 2)
30
30
  assert_equal point.to_latlon, '1,2'
31
31
  end
32
+
33
+ def test_to_wkt
34
+ point = CloudMade::Point.new(1, 2)
35
+ assert_equal point.to_wkt, 'POINT (1 2)'
36
+ end
32
37
  end
33
38
 
34
39
  class LineTest < Test::Unit::TestCase #:nodoc: all
@@ -44,37 +49,63 @@ class LineTest < Test::Unit::TestCase #:nodoc: all
44
49
  line = CloudMade::Line.new([[1.1, 2.0], [0.1, 2.1], [0.5, 3.1], [3.1, 4.1]])
45
50
  assert_equal line.points.length, 4
46
51
  end
52
+
53
+ def test_to_wkt
54
+ line = CloudMade::Line.new([[1.1, 2.0], [0.1, 2.1]])
55
+ assert_equal line.to_wkt, 'LINESTRING (1.1 2.0, 0.1 2.1)'
56
+ end
47
57
  end
48
58
 
49
59
  class MultiLineTest < Test::Unit::TestCase #:nodoc: all
50
- def test_initialization
60
+ def multiline
51
61
  coords = [[[0.2, 35.2], [4.3, 45.1], [5.7, 11.2]], [[1.1, 33.2], [5.3, 22.2]]]
52
- ml = CloudMade::MultiLine.new(coords)
53
- assert_equal ml.lines.size, 2
54
- assert_equal ml.lines[0].points.length, 3
55
- assert_equal ml.lines[1].points.length, 2
56
- assert_equal ml.lines[1].points[0].lon, 33.2
62
+ CloudMade::MultiLine.new(coords)
63
+ end
64
+
65
+ def test_initialization
66
+ assert_equal multiline.lines.size, 2
67
+ assert_equal multiline.lines[0].points.length, 3
68
+ assert_equal multiline.lines[1].points.length, 2
69
+ assert_equal multiline.lines[1].points[0].lon, 33.2
70
+ end
71
+
72
+ def test_to_wkt
73
+ assert_equal multiline.to_wkt, "MULTILINESTRING ((0.2 35.2, 4.3 45.1, 5.7 11.2), (1.1 33.2, 5.3 22.2))"
57
74
  end
58
75
  end
59
76
 
60
77
  class PolygonTest < Test::Unit::TestCase #:nodoc: all
61
- def test_initialization
78
+ def polygon
62
79
  coords = [[[0.2, 35.2], [4.3, 45.1], [5.7, 11.2]], [[1.1, 33.2], [5.3, 22.2]]]
63
- polygon = CloudMade::Polygon.new(coords)
80
+ CloudMade::Polygon.new(coords)
81
+ end
82
+
83
+ def test_initialization
64
84
  assert polygon.border_line != nil
65
85
  assert_equal polygon.border_line.points.size, 3
66
86
  assert polygon.holes != nil
67
87
  assert_equal polygon.holes.size, 1
68
88
  end
89
+
90
+ def test_to_wkt
91
+ assert_equal polygon.to_wkt, 'POLYGON ((0.2 35.2, 4.3 45.1, 5.7 11.2), (1.1 33.2, 5.3 22.2))'
92
+ end
69
93
  end
70
94
 
71
95
  class MultiPolygonTest < Test::Unit::TestCase #:nodoc: all
72
- def test_initialization
96
+ def multipolygon
73
97
  coords = [[[[0.2, 35.2], [4.3, 45.1]]], [[[1.1, 33.2], [5.3, 22.2]]]]
74
- mp = CloudMade::MultiPolygon.new(coords)
75
- assert_equal mp.polygons.size, 2
76
- assert_equal mp.polygons[0].holes.size, 0
77
- assert_equal mp.polygons[1].holes.size, 0
98
+ CloudMade::MultiPolygon.new(coords)
99
+ end
100
+
101
+ def test_initialization
102
+ assert_equal multipolygon.polygons.size, 2
103
+ assert_equal multipolygon.polygons[0].holes.size, 0
104
+ assert_equal multipolygon.polygons[1].holes.size, 0
105
+ end
106
+
107
+ def test_to_wkt
108
+ assert_equal multipolygon.to_wkt, 'MULTIPOLYGON (((0.2 35.2, 4.3 45.1)), ((1.1 33.2, 5.3 22.2)))'
78
109
  end
79
110
  end
80
111
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudmade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-23 00:00:00.000000000 Z
13
+ date: 2012-11-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: test-unit
@@ -55,6 +55,7 @@ extra_rdoc_files:
55
55
  - LICENSE
56
56
  files:
57
57
  - .gitignore
58
+ - .travis.yml
58
59
  - Gemfile
59
60
  - LICENSE
60
61
  - README.md
@@ -91,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  segments:
93
94
  - 0
94
- hash: 2555345038746054796
95
+ hash: -613793366863801681
95
96
  required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -100,10 +101,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  segments:
102
103
  - 0
103
- hash: 2555345038746054796
104
+ hash: -613793366863801681
104
105
  requirements: []
105
106
  rubyforge_project: cloudmade
106
- rubygems_version: 1.8.21
107
+ rubygems_version: 1.8.23
107
108
  signing_key:
108
109
  specification_version: 3
109
110
  summary: CloudMade Ruby API