osrm 0.4.0 → 0.4.1

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: 6c953314975877ae27e5bdd08fbeee9bfa05d81f
4
- data.tar.gz: a94b634022234fe7dcf6526fb0d79416e22749b3
3
+ metadata.gz: 169960f4f55e9adb038d4d74352338acf90947b6
4
+ data.tar.gz: 713c1b28e080c8c48e1f3d3327ae80f2ecf15dc3
5
5
  SHA512:
6
- metadata.gz: 5122640743216979410cad71c32a0a91867564f8745425e61055eb4eb57e2383cf2ea47161f6880406bcaea21e5d8841199a0de3ac876dba4971586400373eae
7
- data.tar.gz: f971c84db9359ca98ec542f191e6e8362c004f7c2ba711ef572e6eb574023e66f5642c6b0a7e31b3d42416e54425fcd9ae83969851c6b4d779ee79c40ca7137f
6
+ metadata.gz: ec89dcde3038a0ad936478b4fe8315494a25bcf4740eecbdaf7b71b8f1c822435385284d761491457b89810ceb00ca177756ea479eb94fb805dfdcd7f6e61238
7
+ data.tar.gz: caa178c62c8ac16d7182da470afa56e58168c698289293a466fa236ff23115561877f9f6d48418322fa5d7226c43e3871efdc6cae96e06edb56884a3f440a300
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ ### OSRM Gem 0.4.1 (2016 Sep 17) ###
4
+
5
+ * Add overview option
6
+
3
7
  ### OSRM Gem 0.4.0 (2016 Sep 17) ###
4
8
 
5
9
  * Upgrade to server API 5
data/README.md CHANGED
@@ -29,7 +29,11 @@ You can [run your own server](https://github.com/Project-OSRM/osrm-backend/wiki)
29
29
  # The cache can be any object providing [] and []= methods.
30
30
  # The cache key must contain the {url} pattern.
31
31
  cache: {}, # Default: nil (no cache)
32
- cache_key: 'my-script:{url}' # Default: 'osrm:{url}'
32
+ cache_key: 'my-script:{url}', # Default: 'osrm:{url}'
33
+
34
+ # Requests
35
+ # Specify the precision of the overview geometries returned
36
+ overview: :full # Possible values: false, :simplified (default), :full
33
37
 
34
38
  )
35
39
 
@@ -12,11 +12,11 @@ module OSRM
12
12
  Configuration.instance
13
13
  end
14
14
 
15
- def self.routes(*locations)
16
- Query.new(*locations).execute
15
+ def self.routes(*locations, overview: nil)
16
+ Query.new(*locations).execute(alternatives: true, overview: overview)
17
17
  end
18
18
 
19
- def self.route(*locations)
20
- routes(*locations).first
19
+ def self.route(*locations, overview: nil)
20
+ Query.new(*locations).execute(alternatives: false, overview: overview).first
21
21
  end
22
22
  end
@@ -16,7 +16,9 @@ module OSRM
16
16
  after_request: nil,
17
17
 
18
18
  cache: nil,
19
- cache_key: 'osrm:{url}'
19
+ cache_key: 'osrm:{url}',
20
+
21
+ overview: :simplified
20
22
  }.freeze
21
23
 
22
24
  DEMO_SERVER = 'router.project-osrm.org'.freeze
@@ -105,6 +107,17 @@ module OSRM
105
107
  ensure_cache_version
106
108
  end
107
109
 
110
+ def overview=(overview)
111
+ ensure_valid_overview(overview)
112
+ @data[:overview] = overview
113
+ end
114
+
115
+ def ensure_valid_overview(overview)
116
+ unless [false, :simplified, :full].include?(overview)
117
+ raise "OSRM API error: Invalid overview type #{overview.inspect}"
118
+ end
119
+ end
120
+
108
121
  # Dynamically add missing accessors
109
122
  DEFAULTS.each do |option, default_value|
110
123
  reader = case default_value
@@ -11,8 +11,8 @@ module OSRM
11
11
  @locations = locations.compact.reject(&:empty?)
12
12
  end
13
13
 
14
- def execute
15
- build_uri
14
+ def execute(alternatives: nil, overview: nil)
15
+ build_uri(alternatives: alternatives, overview: overview)
16
16
  fetch_json_data[:routes].map { |route| Route.new(route) }
17
17
  end
18
18
 
@@ -86,7 +86,7 @@ module OSRM
86
86
  end
87
87
  end
88
88
 
89
- def build_uri
89
+ def build_uri(alternatives: nil, overview: nil)
90
90
  raise "OSRM API error: Server isn't configured" unless configuration.server
91
91
 
92
92
  service = 'route'
@@ -94,9 +94,17 @@ module OSRM
94
94
  profile = 'driving'
95
95
  format = 'json'
96
96
 
97
+ alternatives = alternatives.nil? ? false : (alternatives == true)
98
+ if overview.nil?
99
+ overview = configuration.overview
100
+ else
101
+ configuration.ensure_valid_overview(overview)
102
+ end
103
+
97
104
  params = [
98
- %w(alternatives true),
99
- %w(geometries polyline)
105
+ ['alternatives', alternatives.to_s],
106
+ ['geometries', 'polyline'],
107
+ ['overview', overview.to_s]
100
108
  ]
101
109
 
102
110
  uri_class = configuration.use_ssl? ? URI::HTTPS : URI::HTTP
@@ -6,14 +6,15 @@ module OSRM
6
6
 
7
7
  def initialize(json = {})
8
8
  @geometry = decode_geometry(json[:geometry])
9
- @distance = json[:distance] || 0
10
- @duration = json[:duration] || 0
9
+ @distance = json[:distance].to_f
10
+ @duration = json[:duration].to_f
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def decode_geometry(geometry)
16
- return [] if geometry.nil? || geometry.empty?
16
+ return nil if geometry.nil?
17
+ return [] if geometry.empty?
17
18
 
18
19
  EncodedPolyline.decode_points(geometry, 5).map do |point|
19
20
  point.map { |coordinate| fix_float_precision(coordinate) }
@@ -1,3 +1,3 @@
1
1
  module OSRM
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osrm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Freayd