From 755df6c3425663e7bcfd3e07b6a8976e349c703d Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 30 Mar 2017 19:41:00 +0200 Subject: [PATCH] fix syntax for variable with multiple conditional --- lib/mpw/cli.rb | 21 +++++++++++---------- lib/mpw/config.rb | 15 ++++++++------- lib/mpw/mpw.rb | 17 +++++++++-------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 3f4d43d..0536108 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -317,19 +317,20 @@ class Cli # Display the wallet # @args: wallet -> the wallet name def get_wallet(wallet = nil) - if wallet.to_s.empty? - wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") + @wallet_file = + if wallet.to_s.empty? + wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") - if wallets.length == 1 - @wallet_file = wallets[0] - elsif !@config.default_wallet.to_s.empty? - @wallet_file = "#{@config.wallet_dir}/#{@config.default_wallet}.mpw" + if wallets.length == 1 + wallets[0] + elsif !@config.default_wallet.to_s.empty? + "#{@config.wallet_dir}/#{@config.default_wallet}.mpw" + else + "#{@config.wallet_dir}/default.mpw" + end else - @wallet_file = "#{@config.wallet_dir}/default.mpw" + "#{@config.wallet_dir}/#{wallet}.mpw" end - else - @wallet_file = "#{@config.wallet_dir}/#{wallet}.mpw" - end end # Add a new public key diff --git a/lib/mpw/config.rb b/lib/mpw/config.rb index af746a2..a6c102e 100644 --- a/lib/mpw/config.rb +++ b/lib/mpw/config.rb @@ -38,13 +38,14 @@ class Config def initialize(config_file = nil) @config_file = config_file - if /darwin/ =~ RUBY_PLATFORM - @config_dir = "#{Dir.home}/Library/Preferences/mpw" - elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM - @config_dir = "#{Dir.home}/AppData/Local/mpw" - else - @config_dir = "#{Dir.home}/.config/mpw" - end + @config_dir = + if /darwin/ =~ RUBY_PLATFORM + "#{Dir.home}/Library/Preferences/mpw" + elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM + "#{Dir.home}/AppData/Local/mpw" + else + "#{Dir.home}/.config/mpw" + end @config_file = "#{@config_dir}/mpw.cfg" if @config_file.nil? || @config_file.empty? end diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 46355ec..557d572 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -308,14 +308,15 @@ class MPW # Generate a random password # @args: options -> :length, :special, :alpha, :numeric # @rtrn: a random string - def self.password(options = {}) - if !options.include?(:length) || options[:length].to_i <= 0 - length = 8 - elsif options[:length].to_i >= 32768 - length = 32768 - else - length = options[:length].to_i - end + def self.password(**options) + length = + if !options.include?(:length) || options[:length].to_i <= 0 + 8 + elsif options[:length].to_i >= 32_768 + 32_768 + else + options[:length].to_i + end chars = [] chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]