summaryrefslogtreecommitdiff
path: root/lib/overwrite.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2013-05-29 15:12:52 +0200
committerChristoph Helma <helma@in-silico.ch>2013-05-29 15:12:52 +0200
commitf2ef6216ef785656d799c880f22013f6c7e900e7 (patch)
treefa7d72d434c9cb70483222aa4bc7f580e0bd8fa9 /lib/overwrite.rb
parent0f770837cbfe17fe17fc86aa0d360c55e281c7f7 (diff)
parentef122484598a8979de915344cdeff475cff752c5 (diff)
Merge branch 'development' of github.com:opentox/opentox-client into development
Conflicts: lib/compound.rb
Diffstat (limited to 'lib/overwrite.rb')
-rw-r--r--lib/overwrite.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/overwrite.rb b/lib/overwrite.rb
index d1f3d9d..52b8a9f 100644
--- a/lib/overwrite.rb
+++ b/lib/overwrite.rb
@@ -12,13 +12,14 @@ class Object
end
module Enumerable
+ # @return [Array] only the duplicates of an enumerable
def duplicates
inject({}) {|h,v| h[v]=h[v].to_i+1; h}.reject{|k,v| v==1}.keys
end
end
class String
-
+ # @return [String] converts camel-case to underscore-case (OpenTox::SuperModel -> open_tox/super_model)
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
@@ -88,16 +89,19 @@ module URI
URI.parse(uri).instance_of? URI::HTTPS
end
+ # @return [Boolean] checks if resource exists by making a HEAD-request
def self.accessible?(uri, subjectid=nil)
parsed_uri = URI.parse(uri + (subjectid ? "?subjectid=#{CGI.escape subjectid}" : ""))
http_code = URI.task?(uri) ? 600 : 400
- unless URI.ssl? uri
- Net::HTTP.get_response(parsed_uri).code.to_i < http_code
+ unless (URI.ssl? uri) == true
+ http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
+ request = Net::HTTP::Head.new(parsed_uri.request_uri)
+ http.request(request).code.to_i < http_code
else
http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- request = Net::HTTP::Get.new(parsed_uri.request_uri)
+ request = Net::HTTP::Head.new(parsed_uri.request_uri)
http.request(request).code.to_i < http_code
end
rescue
@@ -114,6 +118,7 @@ module URI
end
class File
+ # @return [String] mime_type including charset using linux cmd command
def mime_type
`file -ib #{self.path}`.chomp
end
@@ -136,6 +141,7 @@ module Kernel
internal_server_error $!.message
end
+ # @return [String] uri of task result, if task fails, an error according to task is raised
def wait_for_task uri
if URI.task?(uri)
t = OpenTox::Task.new uri
@@ -163,7 +169,7 @@ end
class Array
- # Sum of an array for Arrays
+ # Sum up the size of single arrays in an array of arrays
# @param [Array] Array of arrays
# @return [Integer] Sum of size of array elements
def sum_size