From 8ed90c2ddc7de2eac70d36c528869edd8cb846d5 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Wed, 29 Mar 2017 22:50:47 +0200 Subject: [PATCH] fix --- bin/mpw-wallet | 4 ++-- lib/mpw/cli.rb | 6 +++--- lib/mpw/config.rb | 6 +++--- lib/mpw/item.rb | 8 ++++---- lib/mpw/mpw.rb | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bin/mpw-wallet b/bin/mpw-wallet index bcc3fc2..fffeaac 100644 --- a/bin/mpw-wallet +++ b/bin/mpw-wallet @@ -72,9 +72,9 @@ else cli.get_wallet(options[:wallet]) cli.decrypt - if not options[:list_keys].nil? + if !options[:list_keys].nil? cli.list_keys - elsif not options[:gpg_key].nil? + elsif !options[:gpg_key].nil? if options[:delete] cli.delete_key(options[:gpg_key]) else diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 9571fec..6b56c63 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -155,7 +155,7 @@ class Cli items.each do |item| data.each do |k, v| - next if k == :id or k == :otp + next if k == :id || k == :otp v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length] end @@ -240,7 +240,7 @@ class Cli items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase } choice = ask(I18n.t('form.select')).to_i - if choice >= 1 and choice <= items.length + if choice >= 1 && choice <= items.length return items[choice-1] else return nil @@ -331,7 +331,7 @@ class Cli if wallets.length == 1 @wallet_file = wallets[0] - elsif not @config.default_wallet.to_s.empty? + elsif !@config.default_wallet.to_s.empty? @wallet_file = "#{@config.wallet_dir}/#{@config.default_wallet}.mpw" else @wallet_file = "#{@config.wallet_dir}/default.mpw" diff --git a/lib/mpw/config.rb b/lib/mpw/config.rb index 8ec8e3a..cd584b1 100644 --- a/lib/mpw/config.rb +++ b/lib/mpw/config.rb @@ -47,7 +47,7 @@ class Config @config_dir = "#{Dir.home}/.config/mpw" end - @config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? or @config_file.empty? + @config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty? end # Create a new config file @@ -68,7 +68,7 @@ class Config ['numeric', 'special', 'alpha', 'length'].each do |k| if options.has_key?("pwd_#{k}".to_sym) password[k.to_sym] = options["pwd_#{k}".to_sym] - elsif not @password.nil? and @password.has_key?(k.to_sym) + elsif !@password.nil? && @password.has_key?(k.to_sym) password[k.to_sym] = @password[k.to_sym] end end @@ -138,7 +138,7 @@ class Config @gpg_exe = config['gpg_exe'] @password = config['password'] || {} - raise if @gpg_key.empty? or @wallet_dir.empty? + raise if @gpg_key.empty? || @wallet_dir.empty? I18n.locale = @lang.to_sym rescue Exception => e diff --git a/lib/mpw/item.rb b/lib/mpw/item.rb index 7c2547e..c0ca11e 100644 --- a/lib/mpw/item.rb +++ b/lib/mpw/item.rb @@ -37,11 +37,11 @@ class Item # @args: options -> a hash of parameter # raise an error if the hash hasn't the key name def initialize(options={}) - if not options.has_key?(:host) or options[:host].to_s.empty? + if !options.has_key?(:host) || options[:host].to_s.empty? raise I18n.t('error.update.host_empty') end - if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty? + if !options.has_key?(:id) || options[:id].to_s.empty? || !options.has_key?(:created) || options[:created].to_s.empty? @id = generate_id @created = Time.now.to_i else @@ -57,7 +57,7 @@ class Item # Update the item # @args: options -> a hash of parameter def update(options={}) - if options.has_key?(:host) and options[:host].to_s.empty? + if options.has_key?(:host) && options[:host].to_s.empty? raise I18n.t('error.update.host_empty') end @@ -65,7 +65,7 @@ class Item @host = options[:host] if options.has_key?(:host) @protocol = options[:protocol] if options.has_key?(:protocol) @user = options[:user] if options.has_key?(:user) - @port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty? + @port = options[:port].to_i if options.has_key?(:port) && !options[:port].to_s.empty? @otp = options[:otp] if options.has_key?(:otp) @comment = options[:comment] if options.has_key?(:comment) @last_edit = Time.now.to_i unless options.has_key?(:no_update_last_edit) diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 724dcaf..183b888 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -237,7 +237,7 @@ class MPW raise I18n.t('error.bad_class') unless item.instance_of?(Item) raise I18n.t('error.empty') if item.empty? - return @data.push(item) + @data.push(item) end # Search in some csv data @@ -251,12 +251,12 @@ class MPW @data.each do |item| next if item.empty? - next unless group.empty? or group.eql?(item.group.to_s.downcase) + next unless group.empty? || group.eql?(item.group.to_s.downcase) host = item.host.to_s.downcase comment = item.comment.to_s.downcase - next unless host =~ /^.*#{search}.*$/ or comment =~ /^.*#{search}.*$/ + next unless host =~ /^.*#{search}.*$/ || comment =~ /^.*#{search}.*$/ result.push(item) end @@ -315,7 +315,7 @@ class MPW # @args: options -> :length, :special, :alpha, :numeric # @rtrn: a random string def self.password(options={}) - if not options.include?(:length) or options[:length].to_i <= 0 + if !options.include?(:length) || options[:length].to_i <= 0 length = 8 elsif options[:length].to_i >= 32768 length = 32768