routific 1.1.1 → 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/routific/route.rb +39 -21
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f461bbd6a8c76891619ef0e6eac1a430eb5aa7
4
- data.tar.gz: 659b39f98fcd1b8d45d93cbde3b99f59eb8e0a2a
3
+ metadata.gz: a92a096b9aa04f8eed0c72c8b45d4ca262fd6f15
4
+ data.tar.gz: fdfe5a0030a05a98a5427484c4368325a7b16d93
5
5
  SHA512:
6
- metadata.gz: b10a6414354f038e953e4ca3366b8e6322777c92a16c7656b2f02873f49efa80a8499fffe52bc686154bfb39da91cf1b011326845560553db09910c2c7d9d038
7
- data.tar.gz: 50130e568b9c6fd4c5a3bab8212968698b938ca699953d7aaaedbeb84578434fb6bf21606f56a93cbf36ea66cc398342a83a01534e693826bc4f7ce1ee863362
6
+ metadata.gz: d20604a843d68aa9a10bc72ba6e63305b7bb65f0a729c2a58e08dab12c5829ff30eadbe31076d0927c14d351ffe82edf8492ba875bad49c85d6b933afc86ee32
7
+ data.tar.gz: be1a38259698b29c679446377ce38f1d09497cf2be9be87f2f960bf5f9fa4a5df04781f7eab15fe7ad73b4f2c28003ee747f4cc0b84d1213453e882e3f8a077e
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Routific Ruby Gem
2
2
  =================
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/asoesilo/routific-gem.png)](http://travis-ci.org/asoesilo/routific-gem)
4
+ [![Build Status](https://secure.travis-ci.org/routific/routific-gem.png)](http://travis-ci.org/routific/routific-gem)
5
5
 
6
6
  This Ruby Gem assists users to easily access the [Routific API][1], which is a practical and scalable solution to the Vehicle Routing Problem.
7
7
 
@@ -1,18 +1,36 @@
1
1
  module RoutificApi
2
2
  # This class represents the resulting route returned by the Routific API
3
3
  class Route
4
- attr_reader :status, :fitness, :unserved, :vehicleRoutes
4
+ attr_reader :status, :unserved, :vehicleRoutes, :total_travel_time, :total_idle_time
5
5
 
6
6
  # Constructor
7
- def initialize(status, fitness, unserved)
7
+ def initialize(status:, solution: {}, unserved: {}, total_travel_time: 0,
8
+ total_idle_time: 0, total_break_time: 0, total_working_time: 0)
8
9
  @status = status
9
- @fitness = fitness
10
10
  @unserved = unserved
11
- @vehicleRoutes = Hash.new()
11
+ @total_idle_time = total_idle_time
12
+ @total_travel_time = total_travel_time
13
+ @total_break_time = total_break_time
14
+ @total_working_time = total_working_time
15
+
16
+ add_solution(solution)
17
+ end
18
+
19
+ def add_solution(solution)
20
+ @vehicleRoutes = {}
21
+
22
+ solution.each do |vehicle_name, way_points|
23
+ # Get all way points for this vehicle
24
+ way_points.each do |waypoint_info|
25
+ # Get all information for this way point
26
+ way_point = RoutificApi::WayPoint.new(waypoint_info)
27
+ add_way_point(vehicle_name, way_point)
28
+ end
29
+ end
12
30
  end
13
31
 
14
32
  # Adds a new way point for the specified vehicle
15
- def addWayPoint(vehicle_name, way_point)
33
+ def add_way_point(vehicle_name, way_point)
16
34
  if @vehicleRoutes[vehicle_name].nil?
17
35
  # No previous way point was added for the specified vehicle, so create a new array
18
36
  @vehicleRoutes[vehicle_name] = []
@@ -21,26 +39,26 @@ module RoutificApi
21
39
  @vehicleRoutes[vehicle_name] << way_point
22
40
  end
23
41
 
42
+ def number_of_unserved
43
+ @number_of_unserved ||= unserved.count
44
+ end
45
+
24
46
  class << self
25
47
  # Parse the JSON representation of a route, and return it as a Route object
26
- def parse(routeJson)
27
- status = routeJson["status"]
28
- fitness = routeJson["fitness"]
29
- unserved = routeJson["unserved"]
30
- route = RoutificApi::Route.new(status, fitness, unserved)
31
-
32
- # Get way points for each vehicles
33
- routeJson["solution"].each do |vehicle_name, way_points|
34
- # Get all way points for this vehicle
35
- way_points.each do |waypoint_info|
36
- # Get all information for this way point
37
- way_point = RoutificApi::WayPoint.new(waypoint_info)
38
- route.addWayPoint(vehicle_name, way_point)
39
- end
48
+ def parse(data)
49
+ data = process_data(data)
50
+ RoutificApi::Route.new(data)
51
+ end
52
+
53
+ def process_data(hash)
54
+ hash.keys.each do |key|
55
+ hash[(key.to_sym rescue key) || key] = hash.delete(key)
40
56
  end
41
57
 
42
- # Return the resulting Route object
43
- route
58
+ hash.delete(:num_unserved)
59
+ hash.delete(:unserved) if hash[:unserved] == nil
60
+
61
+ hash
44
62
  end
45
63
  end
46
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routific
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Kuo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-12 00:00:00.000000000 Z
12
+ date: 2017-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.11'
84
84
  description: Gem to use Routific API
85
- email: asoesilo@live.com
85
+ email: andre@routific.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -99,7 +99,7 @@ homepage: https://routific.com/
99
99
  licenses:
100
100
  - MIT
101
101
  metadata:
102
- source_code: https://github.com/asoesilo/routific-gem
102
+ source_code: https://github.com/routific/routific-gem
103
103
  post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths: