From 00cffad79e7e97fe7d0c02e239d89aa45ab3583f Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Sat, 16 Jan 2016 11:05:04 +0100 Subject: [PATCH] Added some syntactic suguar (used in rubocop cops). --- app/controllers/long_polling_controller.rb | 2 +- app/models/application_model.rb | 6 +++--- app/models/channel/driver/imap.rb | 2 +- app/models/channel/driver/pop3.rb | 2 +- app/models/channel/email_parser.rb | 4 ++-- app/models/chat.rb | 2 +- lib/encode.rb | 2 +- lib/import/zendesk.rb | 2 +- lib/models.rb | 6 +++--- lib/report/base.rb | 6 +++--- lib/stats/ticket_channel_distribution.rb | 4 ++-- lib/stats/ticket_escalation.rb | 2 +- script/websocket-server.rb | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index f5b50c9f4..0df058b34 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -89,7 +89,7 @@ class LongPollingController < ApplicationController sleep 0.25 } #sleep 2 - if count == 0 + if count.zero? render json: { event: 'pong' } return end diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 548c234de..03707301e 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -442,7 +442,7 @@ returns # do lookup with == to handle case insensitive databases records = where(login: data[:login]) records.each {|loop_record| - if loop_record.login.casecmp(data[:login]) == 0 + if loop_record.login.casecmp(data[:login]).zero? loop_record.update_attributes(data) return loop_record end @@ -455,7 +455,7 @@ returns # do lookup with == to handle case insensitive databases records = where(email: data[:email]) records.each {|loop_record| - if loop_record.email.casecmp(data[:email]) == 0 + if loop_record.email.casecmp(data[:email]).zero? loop_record.update_attributes(data) return loop_record end @@ -468,7 +468,7 @@ returns # do lookup with == to handle case insensitive databases records = where(locale: data[:locale]) records.each {|loop_record| - if loop_record.locale.casecmp(data[:locale]) == 0 + if loop_record.locale.casecmp(data[:locale]).zero? loop_record.update_attributes(data) return loop_record end diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index dd723aa9e..644222336 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -182,7 +182,7 @@ returns end @imap.expunge() disconnect - if count == 0 + if count.zero? Rails.logger.info ' - no message' end Rails.logger.info 'done' diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index 99514277e..ac64365fa 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -151,7 +151,7 @@ returns end end disconnect - if count == 0 + if count.zero? Rails.logger.info ' - no message' end Rails.logger.info 'done' diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index f9a835296..3412db4e3 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -193,7 +193,7 @@ class Channel::EmailParser # not multipart email # text part only - elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain') == 0 + elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain').zero? data[:body] = mail.body.decoded data[:body] = Encode.conv(mail.charset, data[:body]) @@ -204,7 +204,7 @@ class Channel::EmailParser # html part only, convert to text and add it as attachment else filename = '-no name-' - if mail.mime_type.to_s.casecmp('text/html') == 0 + if mail.mime_type.to_s.casecmp('text/html').zero? filename = 'message.html' data[:body] = mail.body.decoded data[:body] = Encode.conv(mail.charset, data[:body]) diff --git a/app/models/chat.rb b/app/models/chat.rb index 5a117aa44..ee0320cd6 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -46,7 +46,7 @@ class Chat < ApplicationModel # check if agents are available available_agents = Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - 2.minutes).count - if available_agents == 0 + if available_agents.zero? return { state: 'offline' } end diff --git a/lib/encode.rb b/lib/encode.rb index 79b3a2c53..edc3b2904 100644 --- a/lib/encode.rb +++ b/lib/encode.rb @@ -11,7 +11,7 @@ module Encode end # validate already existing utf8 strings - if charset.casecmp('utf8') == 0 || charset.casecmp('utf-8') == 0 + if charset.casecmp('utf8').zero? || charset.casecmp('utf-8').zero? begin # return if encoding is valid diff --git a/lib/import/zendesk.rb b/lib/import/zendesk.rb index c6702394c..e04326d8d 100644 --- a/lib/import/zendesk.rb +++ b/lib/import/zendesk.rb @@ -635,7 +635,7 @@ module Import::Zendesk zendesk_attachments = zendesk_article.attachments - next if zendesk_attachments.size == 0 + next if zendesk_attachments.size.zero? local_attachments = local_article.attachments diff --git a/lib/models.rb b/lib/models.rb index 01d78617c..4b7fb4541 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -124,7 +124,7 @@ returns next if !model_attributes[:attributes].include?(item) count = model_class.where("#{item} = ?", object_id).count - next if count == 0 + next if count.zero? if !references[model_class.to_s][item] references[model_class.to_s][item] = 0 end @@ -144,7 +144,7 @@ returns if reflection_value.options[:class_name] == object_name count = model_class.where("#{col_name} = ?", object_id).count - next if count == 0 + next if count.zero? if !references[model_class.to_s][col_name] references[model_class.to_s][col_name] = 0 end @@ -156,7 +156,7 @@ returns next if reflection_value.name != object_name.downcase.to_sym count = model_class.where("#{col_name} = ?", object_id).count - next if count == 0 + next if count.zero? if !references[model_class.to_s][col_name] references[model_class.to_s][col_name] = 0 end diff --git a/lib/report/base.rb b/lib/report/base.rb index cdeb7457d..249102146 100644 --- a/lib/report/base.rb +++ b/lib/report/base.rb @@ -242,7 +242,7 @@ class Report::Base time_total = time_total + diff tickets += 1 } - if time_total == 0 || tickets == 0 + if time_total.zero? || tickets.zero? tickets = -0.001 else tickets = time_total / tickets / 60 @@ -279,7 +279,7 @@ class Report::Base time_min = diff end } - tickets = if time_min == 0 + tickets = if time_min.zero? -0.001 else (time_min / 60).to_i @@ -317,7 +317,7 @@ class Report::Base time_max = diff end } - tickets = if time_max == 0 + tickets = if time_max.zero? -0.001 else (time_max / 60).to_i diff --git a/lib/stats/ticket_channel_distribution.rb b/lib/stats/ticket_channel_distribution.rb index f56c518ee..fdebba8ee 100644 --- a/lib/stats/ticket_channel_distribution.rb +++ b/lib/stats/ticket_channel_distribution.rb @@ -67,7 +67,7 @@ class Stats::TicketChannelDistribution channels.each {|channel| count = result[channel[:sender].to_sym][:inbound] #puts "#{channel.inspect}:in/#{result.inspect}:#{count}" - in_process_precent = if count == 0 + in_process_precent = if count.zero? 0 else (count * 1000) / ((total_in * 1000) / 100) @@ -75,7 +75,7 @@ class Stats::TicketChannelDistribution result[channel[:sender].to_sym][:inbound_in_percent] = in_process_precent count = result[channel[:sender].to_sym][:outbound] - out_process_precent = if count == 0 + out_process_precent = if count.zero? 0 else (count * 1000) / ((total_out * 1000) / 100) diff --git a/lib/stats/ticket_escalation.rb b/lib/stats/ticket_escalation.rb index abe359a04..1cc2a25b5 100644 --- a/lib/stats/ticket_escalation.rb +++ b/lib/stats/ticket_escalation.rb @@ -21,7 +21,7 @@ class Stats::TicketEscalation average = '-' state = 'supergood' - state = if own_escalated == 0 + state = if own_escalated.zero? 'supergood' elsif own_escalated <= 1 'good' diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 323ce8746..485c1528d 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -206,7 +206,7 @@ EventMachine.run { } EventMachine.add_periodic_timer(0.4) { - next if @clients.size == 0 + next if @clients.size.zero? #log 'debug', 'checking for data to send...' @clients.each { |client_id, client| next if client[:disconnect]