Navigation Menu

Skip to content

Commit

Permalink
Use "case when"
Browse files Browse the repository at this point in the history
"case XXX when ..." is more readable rather than "if XXX ... elsif XXX
..."  because condition target ("XXX" in this case) is clear.
  • Loading branch information
kou committed Apr 15, 2015
1 parent 27721ed commit ddc500f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/drntest/directive.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2013 Droonga Project
# Copyright (C) 2013-2015 Droonga Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -81,13 +81,14 @@ def initialize(parameters)
@timeout_seconds = nil

parameters.each do |parameter|
if parameter =~ /\A(\d+)(?:messages|msg)?\z/
case parameter
when /\A(\d+)(?:messages|msg)?\z/
@max_messages = $1.to_i
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
when /\A(\d+\.?|\.\d+|\d+\.\d+)s(?:ec(?:onds?)?)?\z/
@timeout_seconds = $1.to_f
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
when /\A(\d+\.?|\.\d+|\d+\.\d+)m(?:inutes?)?\z/
@timeout_seconds = $1.to_f * ONE_MINUTE_IN_SECONDS
elsif parameter =~ /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
when /\A(\d+\.?|\.\d+|\d+\.\d+)h(?:ours?)?\z/
@timeout_seconds = $1.to_f * ONE_HOUR_IN_SECONDS
end
end
Expand Down

0 comments on commit ddc500f

Please sign in to comment.