X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Flib%2Fmaasha%2Fbiopieces.rb;h=1797d9211ed4e16ddcc1101b86d1170437ae314f;hb=c4b49c5ce1ed3b46ae37e6ebd73c21d67d6d4810;hp=bd85afb0f4a86c02eaaa8a0dc07324489d8ed6f0;hpb=5a9b7c80e4e4428e404575ed3c0290cde15a7402;p=biopieces.git diff --git a/code_ruby/lib/maasha/biopieces.rb b/code_ruby/lib/maasha/biopieces.rb index bd85afb..1797d92 100644 --- a/code_ruby/lib/maasha/biopieces.rb +++ b/code_ruby/lib/maasha/biopieces.rb @@ -233,7 +233,7 @@ class Casts < Array def check_keys @cast_list.each do |cast| MANDATORY.each do |mandatory| - raise CastError, "Missing symbol in cast: '#{mandatory.to_sym}'" unless cast.has_key? mandatory.to_sym + raise CastError, "Missing symbol in cast: '#{mandatory}'" unless cast.has_key? mandatory.to_sym end end end @@ -272,7 +272,7 @@ class Casts < Array type_hash[type] = true end - unless type_hash.has_key? cast[:type] + unless type_hash[cast[:type]] raise CastError, "Illegal cast of type: '#{cast[:type]}'" end end @@ -312,8 +312,8 @@ class Casts < Array def check_duplicates check_hash = {} @cast_list.each do |cast| - raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash.has_key? cast[:long] - raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash.has_key? cast[:short] + raise CastError, "Duplicate argument: '--#{cast[:long]}'" if check_hash[cast[:long]] + raise CastError, "Duplicate argument: '-#{cast[:short]}'" if check_hash[cast[:short]] check_hash[cast[:long]] = true check_hash[cast[:short]] = true end @@ -446,7 +446,7 @@ class OptionHandler def options_default @casts.each do |cast| if cast[:default] - unless @options.has_key? cast[:long] + unless @options[cast[:long]] if cast[:type] == 'list' @options[cast[:long]] = cast[:default].split ',' else @@ -462,7 +462,7 @@ class OptionHandler def options_glob @casts.each do |cast| if cast[:type] == 'files' or cast[:type] == 'files!' - if @options.has_key? cast[:long] + if @options[cast[:long]] files = [] @options[cast[:long]].each do |path| @@ -498,13 +498,13 @@ class OptionHandler # Check if a mandatory option is set and raise if it isn't. def options_check_mandatory(cast) if cast[:mandatory] - raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options.has_key? cast[:long] + raise ArgumentError, "Mandatory argument: --#{cast[:long]}" unless @options[cast[:long]] end end # Check int type option and raise if not an integer. def options_check_int(cast) - if cast[:type] == 'int' and @options.has_key? cast[:long] + if cast[:type] == 'int' and @options[cast[:long]] unless @options[cast[:long]].is_a? Integer raise ArgumentError, "Argument to --#{cast[:long]} must be an integer, not '#{@options[cast[:long]]}'" end @@ -513,7 +513,7 @@ class OptionHandler # Check uint type option and raise if not an unsinged integer. def options_check_uint(cast) - if cast[:type] == 'uint' and @options.has_key? cast[:long] + if cast[:type] == 'uint' and @options[cast[:long]] unless @options[cast[:long]].is_a? Integer and @options[cast[:long]] >= 0 raise ArgumentError, "Argument to --#{cast[:long]} must be an unsigned integer, not '#{@options[cast[:long]]}'" end @@ -522,14 +522,14 @@ class OptionHandler # Check file! type argument and raise if file don't exists. def options_check_file(cast) - if cast[:type] == 'file!' and @options.has_key? cast[:long] + if cast[:type] == 'file!' and @options[cast[:long]] raise ArgumentError, "No such file: '#{@options[cast[:long]]}'" unless File.file? @options[cast[:long]] end end # Check files! type argument and raise if files don't exists. def options_check_files(cast) - if cast[:type] == 'files!' and @options.has_key? cast[:long] + if cast[:type] == 'files!' and @options[cast[:long]] @options[cast[:long]].each do |path| next if path == "-" raise ArgumentError, "File not readable: '#{path}'" unless File.readable? path @@ -539,24 +539,24 @@ class OptionHandler # Check dir! type argument and raise if directory don't exist. def options_check_dir(cast) - if cast[:type] == 'dir!' and @options.has_key? cast[:long] + if cast[:type] == 'dir!' and @options[cast[:long]] raise ArgumentError, "No such directory: '#{@options[cast[:long]]}'" unless File.directory? @options[cast[:long]] end end # Check options and raise unless allowed. def options_check_allowed(cast) - if cast[:allowed] and @options.has_key? cast[:long] + if cast[:allowed] and @options[cast[:long]] allowed_hash = {} cast[:allowed].split(',').each { |a| allowed_hash[a.to_s] = 1 } - raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash.has_key? @options[cast[:long]].to_s + raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} not allowed" unless allowed_hash[@options[cast[:long]].to_s] end end # Check disallowed argument values and raise if disallowed. def options_check_disallowed(cast) - if cast[:disallowed] and @options.has_key? cast[:long] + if cast[:disallowed] and @options[cast[:long]] cast[:disallowed].split(',').each do |val| raise ArgumentError, "Argument '#{@options[cast[:long]]}' to --#{cast[:long]} is disallowed" if val.to_s == @options[cast[:long]].to_s end