Skip to content

Commit 147d4df

Browse files
jimvmandreastt
authored andcommitted
rb: replace duplicated type/value mapping
Replace two case statements with a hash. Signed-off-by: Andreas Tolfsen <[email protected]>
1 parent e4b33f3 commit 147d4df

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

rb/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb

+16-29
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,28 @@ module HasNetworkConnection
55
def network_connection_type
66
connection_value = @bridge.getNetworkConnection
77

8-
# Convert connection value to type. In case the connection type is
9-
# not recognized return the connection value.
10-
case connection_value
11-
when 1
12-
:airplane_mode
13-
when 2
14-
:wifi
15-
when 4
16-
:data
17-
when 6
18-
:all
19-
when 0
20-
:none
21-
else
22-
connection_value
23-
end
8+
connection_type = values_to_type[connection_value]
9+
10+
# In case the connection type is not recognized return the
11+
# connection value.
12+
connection_type || connection_value
2413
end
2514

2615
def network_connection_type=(connection_type)
27-
# convert connection type to value
28-
connection_value = case connection_type
29-
when :airplane_mode
30-
1
31-
when :wifi
32-
2
33-
when :data
34-
4
35-
when :all
36-
6
37-
when :none
38-
0
39-
end
16+
connection_value = type_to_values[connection_type]
4017

4118
@bridge.setNetworkConnection connection_value
4219
end
20+
21+
private
22+
23+
def type_to_values
24+
{:airplane_mode => 1, :wifi => 2, :data => 4, :all => 6, :none => 0}
25+
end
26+
27+
def values_to_type
28+
type_to_values.invert
29+
end
4330
end
4431
end
4532
end

0 commit comments

Comments
 (0)