From c08ae995464c3cf23202ec165bcf3889ca439fff Mon Sep 17 00:00:00 2001 From: evilsocket Date: Fri, 26 Feb 2016 18:45:52 +0100 Subject: [PATCH] Refactored if/then constructs to ternary operators. --- lib/bettercap/discovery/thread.rb | 4 ++-- lib/bettercap/network/target.rb | 14 +++++++------- lib/bettercap/proxy/modules/injectcss.rb | 2 +- lib/bettercap/proxy/modules/injectjs.rb | 2 +- lib/bettercap/proxy/sslstrip/strip.rb | 2 +- lib/bettercap/update_checker.rb | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/bettercap/discovery/thread.rb b/lib/bettercap/discovery/thread.rb index 4c3927fd..bfb23611 100644 --- a/lib/bettercap/discovery/thread.rb +++ b/lib/bettercap/discovery/thread.rb @@ -71,13 +71,13 @@ def print_differences( prev ) if diff[:new].empty? snew = "" else - snew = "Acquired #{diff[:new].size} new target#{if diff[:new].size > 1 then "s" else "" end}" + snew = "Acquired #{diff[:new].size} new target#{diff[:new].size > 1 ? "s" : ""}" end if diff[:lost].empty? slost = "" else - slost = "#{if snew == "" then 'L' else ', l' end}ost #{diff[:lost].size} target#{if diff[:lost].size > 1 then "s" else "" end}" + slost = "#{snew.empty?? 'L' : ', l'}ost #{diff[:lost].size} target#{diff[:lost].size > 1 ? "s" : ""}" end Logger.info "#{snew}#{slost} :" diff --git a/lib/bettercap/network/target.rb b/lib/bettercap/network/target.rb index 23154765..888cbb80 100644 --- a/lib/bettercap/network/target.rb +++ b/lib/bettercap/network/target.rb @@ -76,13 +76,13 @@ def mac=(value) # Return a verbose string representation of this object. def to_s(padding=true) - if padding - s = sprintf( '%-15s : %-17s', if @ip.nil? then '???' else @ip end, @mac ) - else - s = sprintf( '%s : %s', if @ip.nil? then '???' else @ip end, @mac ) - end + address = @ip.nil?? '???' : @ip + fmt = padding ? '%-15s : %-17s' : '%s : %s' + vendor = @vendor.nil?? " ( ??? )" : " ( #{@vendor} )" + + s = sprintf( fmt, address, @mac ) s += " / #{@hostname}" unless @hostname.nil? - s += if @vendor.nil? then " ( ??? )" else " ( #{@vendor} )" end + s += vendor s end @@ -111,7 +111,7 @@ def equals?(ip, mac) end def self.normalized_mac(v) - v.split(':').map { |e| if e.size == 2 then e.upcase else "0#{e.upcase}" end }.join(':') + v.split(':').map { |e| e.size == 2 ? e.upcase : "0#{e.upcase}" }.join(':') end private diff --git a/lib/bettercap/proxy/modules/injectcss.rb b/lib/bettercap/proxy/modules/injectcss.rb index fa0eefc8..717a61e4 100644 --- a/lib/bettercap/proxy/modules/injectcss.rb +++ b/lib/bettercap/proxy/modules/injectcss.rb @@ -56,7 +56,7 @@ def initialize def on_request( request, response ) # is it a html page? if response.content_type =~ /^text\/html.*/ - BetterCap::Logger.info "[#{'INJECTCSS'.green}] Injecting CSS #{if @@cssdata.nil? then "URL" else "file" end} into #{request.to_url}" + BetterCap::Logger.info "[#{'INJECTCSS'.green}] Injecting CSS #{@@cssdata.nil?? "URL" : "file"} into #{request.to_url}" # inject URL if @@cssdata.nil? response.body.sub!( '', " " ) diff --git a/lib/bettercap/proxy/modules/injectjs.rb b/lib/bettercap/proxy/modules/injectjs.rb index f0560859..6c6e62b0 100644 --- a/lib/bettercap/proxy/modules/injectjs.rb +++ b/lib/bettercap/proxy/modules/injectjs.rb @@ -56,7 +56,7 @@ def initialize def on_request( request, response ) # is it a html page? if response.content_type =~ /^text\/html.*/ - BetterCap::Logger.info "[#{'INJECTJS'.green}] Injecting javascript #{if @@jsdata.nil? then "URL" else "file" end} into #{request.to_url}" + BetterCap::Logger.info "[#{'INJECTJS'.green}] Injecting javascript #{@@jsdata.nil?? "URL" : "file"} into #{request.to_url}" # inject URL if @@jsdata.nil? response.body.sub!( '', "" ) diff --git a/lib/bettercap/proxy/sslstrip/strip.rb b/lib/bettercap/proxy/sslstrip/strip.rb index c35b305d..f43c8973 100644 --- a/lib/bettercap/proxy/sslstrip/strip.rb +++ b/lib/bettercap/proxy/sslstrip/strip.rb @@ -293,7 +293,7 @@ def process_body!(request, response) rescue; end unless links.empty? - Logger.info "[#{'SSLSTRIP'.green} #{request.client}] Stripping #{links.size} HTTPS link#{if links.size > 1 then 's' else '' end} inside '#{request.to_url}'." + Logger.info "[#{'SSLSTRIP'.green} #{request.client}] Stripping #{links.size} HTTPS link#{links.size > 1 ? 's' : ''} inside '#{request.to_url}'." links.each do |l| original, stripped = l diff --git a/lib/bettercap/update_checker.rb b/lib/bettercap/update_checker.rb index 78f5b8bd..db922648 100644 --- a/lib/bettercap/update_checker.rb +++ b/lib/bettercap/update_checker.rb @@ -32,7 +32,7 @@ def self.check def self.vton v vi = 0.0 v.split('.').reverse.each_with_index do |e,i| - vi += ( e.to_i * 10**i ) - ( if e =~ /[\d+]b/ then 0.5 else 0 end ) + vi += ( e.to_i * 10**i ) - ( e =~ /[\d+]b/ ? 0.5 : 0 ) end vi end