Simplify the code by using a ternary operator.

master
Robert "ar" Gerus 2013-05-23 08:28:49 +02:00
parent 6feefbe592
commit c5b5c9b775
1 changed files with 3 additions and 7 deletions

10
up.rb
View File

@ -15,15 +15,11 @@ ARGV.each do |path|
# add the dot here, so that if we get a file without dot, we don't have
# to conditionally add the dot later on
ext = "." + path.sub(/.*[.]([^.]*)/, '\1') if path.match(/[^.]+[.][^.]+/)
# make sure ext isn't nil
ext = ext.nil? ? "" : ext
content = open(path).read
md5 = Digest::MD5.hexdigest(content)
# basically a glorified syntax sugar for (ext.nil? ? "" : ext)
begin
Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
# we probably tried to add nil to a string ("ext" could possibly be nil)
rescue TypeError
Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5)
end
Net::SCP.upload!(HOST, USERNAME, StringIO.new(content), UPLOAD_BASE_PATH + md5 + ext)
printf("%s\t=> %s%s%s\n", path, LINK_BASE_PATH, md5, ext)
}
end