Skip to content

Commit

Permalink
chore: Conformance To Style Standards With RuboCop & TravisCI (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanunruh authored Sep 1, 2020
1 parent b8fd2a2 commit 2cae1b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
7 changes: 3 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,3 +26,6 @@ CyclomaticComplexity:

PerceivedComplexity:
Max: 11

Metrics/LineLength:
Max: 100
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ install:
gem install bundler:1.14.6; bundle install

test:
rubocop
rake test
41 changes: 20 additions & 21 deletions lib/smtpapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
4 changes: 2 additions & 2 deletions smtpapi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 2cae1b5

Please sign in to comment.