Skip to content

Commit

Permalink
rb: replace duplicated type/value mapping
Browse files Browse the repository at this point in the history
Replace two case statements with a hash.

Signed-off-by: Andreas Tolfsen <[email protected]>
  • Loading branch information
jimvm authored and andreastt committed Mar 2, 2015
1 parent e4b33f3 commit 147d4df
Showing 1 changed file with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,28 @@ module HasNetworkConnection
def network_connection_type
connection_value = @bridge.getNetworkConnection

# Convert connection value to type. In case the connection type is
# not recognized return the connection value.
case connection_value
when 1
:airplane_mode
when 2
:wifi
when 4
:data
when 6
:all
when 0
:none
else
connection_value
end
connection_type = values_to_type[connection_value]

# In case the connection type is not recognized return the
# connection value.
connection_type || connection_value
end

def network_connection_type=(connection_type)
# convert connection type to value
connection_value = case connection_type
when :airplane_mode
1
when :wifi
2
when :data
4
when :all
6
when :none
0
end
connection_value = type_to_values[connection_type]

@bridge.setNetworkConnection connection_value
end

private

def type_to_values
{:airplane_mode => 1, :wifi => 2, :data => 4, :all => 6, :none => 0}
end

def values_to_type
type_to_values.invert
end
end
end
end
Expand Down

0 comments on commit 147d4df

Please sign in to comment.