Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 44.74 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | module Route4me |
||
2 | class OptimizationProblem |
||
3 | def self.url |
||
4 | '/api.v4/optimization_problem.php' |
||
5 | end |
||
6 | |||
7 | def self.get(params={}) |
||
8 | get = Util.extract(params, [ |
||
9 | :optimization_problem_id, :wait_for_final_state, |
||
10 | :state, :limit, :offset |
||
11 | ]) |
||
12 | |||
13 | optimization = Route4me.request(:get, self.url, get: get) |
||
14 | if (optimization[:optimizations]).nil? |
||
15 | optimization |
||
16 | else |
||
17 | optimization[:optimizations] |
||
18 | end |
||
19 | end |
||
20 | |||
21 | View Code Duplication | def self.optimize(params={}) |
|
|
|||
22 | json = Util.extract(params, [:addresses, :parameters]) |
||
23 | get = Util.extract(params, [ |
||
24 | :directions, :format, :route_path_output, :optimized_callback_url |
||
25 | ]) |
||
26 | |||
27 | Route4me.request(:post, self.url, get: get, json: json) |
||
28 | end |
||
29 | |||
30 | View Code Duplication | def self.update(params={}) |
|
31 | json = Util.extract(params, [:addresses, :parameters]) |
||
32 | get = Util.extract(params, [ |
||
33 | :optimization_problem_id, :directions, :format, |
||
34 | :route_path_output, :reoptimize |
||
35 | ]) |
||
36 | |||
37 | Route4me.request(:post, self.url, get: get, json: json) |
||
38 | end |
||
39 | end |
||
40 | end |
||
41 |