Skip to content

Commit

Permalink
implement rubocop code edits
Browse files Browse the repository at this point in the history
  • Loading branch information
alanunruh committed Oct 8, 2018
1 parent 41300f4 commit f89d2c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions lib/smtpapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 @@ -134,25 +154,5 @@ def to_array

data
end

protected :to_array

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
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 'bundler', '~> 1.5'
Expand Down

0 comments on commit f89d2c4

Please sign in to comment.