From cd1cba67830505cd2d23ec83e64c0beed42a9f28 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Wed, 22 Jul 2015 20:08:12 +0200 Subject: mongo batch import workaround --- lib/overwrite.rb | 142 ++++++++++--------------------------------------------- 1 file changed, 24 insertions(+), 118 deletions(-) (limited to 'lib/overwrite.rb') diff --git a/lib/overwrite.rb b/lib/overwrite.rb index 4dafe8d..2eb0b39 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -36,61 +36,40 @@ class String bad_request_error "invalid value for Boolean: \"#{self}\"" end - # encloses URI in text with with link tag - # @return [String] new text with marked links - def link_urls - self.gsub(/(?i)http(s?):\/\/[^\r\n\s']*/, '\0') - end - - # produces a html page for making web services browser friendly - # format of text (=string params) is preserved (e.g. line breaks) - # urls are marked as links - # - # @param related_links [optional,String] uri on related resources - # @param description [optional,String] general info - # @param png_image [optional,String] imagename - # @return [String] html page - def to_html(related_links=nil, description=nil, png_image=nil ) - - # TODO add title as parameter - title = nil #$sinatra.to($sinatra.request.env['PATH_INFO'], :full) if $sinatra - html = "" - html << ""+title+"" if title - #html += "<\/img>" - - html << "

Description

"+description.link_urls+"

" if description - html << "

Related links

"+related_links.link_urls+"

" if related_links - html << "

Content

" if description || related_links - html << "

" - html << "\n" if png_image - html << self.link_urls - html << "

" - html - end +end - def uri? - URI.valid?(self) +class File + # @return [String] mime_type including charset using linux cmd command + def mime_type + `file -ib '#{self.path}'`.chomp end - end -module URI +class Array - def self.compound? uri - uri =~ /compound/ and URI.valid? uri + # 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 + self.inject(0) { |s,a| + if a.respond_to?('size') + s+=a.size + else + internal_server_error "No size available: #{a.inspect}" + end + } end - def self.task? uri - uri =~ /task/ and URI.valid? uri + # For symbolic features + # @param [Array] Array to test. + # @return [Boolean] Whether the array has just one unique value. + def zero_variance? + return self.uniq.size == 1 end - def self.dataset? uri - uri =~ /dataset/ and URI.accessible? uri - end +end - def self.model? uri - uri =~ /model/ and URI.accessible? uri - end +module URI def self.ssl? uri URI.parse(uri).instance_of? URI::HTTPS @@ -124,76 +103,3 @@ module URI end end - -class File - # @return [String] mime_type including charset using linux cmd command - def mime_type - `file -ib '#{self.path}'`.chomp - end -end - -module Kernel - -=begin - # overwrite backtick operator to catch system errors - # Override raises an error if _cmd_ returns a non-zero exit status. CH: I do not understand this comment - # Returns stdout if _cmd_ succeeds. Note that these are simply concatenated; STDERR is not inline. CH: I do not understand this comment - def ` cmd - stdout, stderr = '' - status = Open4::popen4(cmd) do |pid, stdin_stream, stdout_stream, stderr_stream| - stdout = stdout_stream.read - stderr = stderr_stream.read - end - internal_server_error "`" + cmd + "` failed.\n" + stdout + stderr unless status.success? - return stdout - rescue - internal_server_error $!.message - end -=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 - t.wait - unless t.completed? - error = OpenTox::RestClientWrapper.known_errors.select{|error| error[:code] == t.code}.first - error_method = error ? error[:method] : :internal_server_error - report = t.error_report - error_message = report ? report[:message] : $!.message - error_cause = report ? report[:errorCause] : nil - Object.send(error_method,error_message,t.uri,error_cause) - end - uri = t.resultURI - end - uri - end - - -end - - -class Array - - # 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 - self.inject(0) { |s,a| - if a.respond_to?('size') - s+=a.size - else - internal_server_error "No size available: #{a.inspect}" - end - } - end - - # For symbolic features - # @param [Array] Array to test. - # @return [Boolean] Whether the array has just one unique value. - def zero_variance? - return self.uniq.size == 1 - end - -end - -- cgit v1.2.3