From 2cae1b577db42a9f14af2e631086781f9accae32 Mon Sep 17 00:00:00 2001 From: Alan Unruh Date: Tue, 1 Sep 2020 12:14:52 -0400 Subject: [PATCH] chore: Conformance To Style Standards With RuboCop & TravisCI (#71) --- .rubocop.yml | 7 +++---- Makefile | 1 + lib/smtpapi.rb | 41 ++++++++++++++++++++--------------------- smtpapi.gemspec | 4 ++-- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ba8db28..7471b44 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,10 +16,6 @@ ParameterLists: AbcSize: Max: 34 -# Increase max number of "/" in %r -RegexpLiteral: - MaxSlashes: 0 - # Increase the max line number of class ClassLength: Max: 250 @@ -30,3 +26,6 @@ CyclomaticComplexity: PerceivedComplexity: Max: 11 + +Metrics/LineLength: + Max: 100 diff --git a/Makefile b/Makefile index de385d2..4103abb 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,5 @@ install: gem install bundler:1.14.6; bundle install test: + rubocop rake test diff --git a/lib/smtpapi.rb b/lib/smtpapi.rb index f2f10e5..6a0e1b7 100644 --- a/lib/smtpapi.rb +++ b/lib/smtpapi.rb @@ -111,6 +111,26 @@ def set_ip_pool(pool_name) self end + def json_string + escape_unicode(to_array.to_json) + end + alias_method :to_json, :json_string + + def escape_unicode(str) + str.unpack('U*').map do |i| + if i > 65_535 + "\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}" \ + "\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}" + elsif i > 127 + "\\u#{format('%04x', i)}" + else + i.chr('UTF-8') + end + end.join + end + + protected + def to_array data = {} data['to'] = @to unless @to.empty? @@ -132,26 +152,5 @@ def to_array data end - - protected :to_array - - def json_string - escape_unicode(to_array.to_json) - end - - alias :to_json :json_string - - def escape_unicode(str) - str.unpack('U*').map do |i| - if i > 65_535 - "\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}" \ - "\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}" - elsif i > 127 - "\\u#{format('%04x', i)}" - else - i.chr('UTF-8') - end - end.join - end end end diff --git a/smtpapi.gemspec b/smtpapi.gemspec index 0ac658a..6de211e 100644 --- a/smtpapi.gemspec +++ b/smtpapi.gemspec @@ -13,8 +13,8 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.files = `git ls-files -z`.split("\x0") - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) } + spec.test_files = spec.files.grep(/^(test|spec|features)/) spec.require_paths = ['lib'] spec.add_development_dependency 'rake'