From 9119cb4f3fbcedb5c233b0a1f3fe1398fcc0e193 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 28 Jun 2012 12:24:52 +0000 Subject: modified assignment operator --- lib/opentox.rb | 24 +++++++++++++++++++++--- lib/overwrite.rb | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/opentox.rb b/lib/opentox.rb index f79b51b..6df16fa 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -46,11 +46,22 @@ module OpenTox result end + def []=(key,value) + uri = RDF::URI.new(@uri) + #@rdf.delete [uri,key,nil] + #result = @rdf.query([RDF::URI.new(@uri),key,nil]).collect{|statement| statement.object} + @rdf << [uri, key, value] + end + + #def []<<(key,value) + #@rdf << [RDF::URI.new(@uri), key, value] + #end + # Save object at service def save put self.to_ntriples, { :content_type => "text/plain"} - rescue # fall back to rdfxml - put self.to_rdfxml, { :content_type => "application/rdf+xml"} + #rescue # fall back to rdfxml + #put self.to_rdfxml, { :content_type => "application/rdf+xml"} end RDF_FORMATS.each do |format| @@ -113,8 +124,15 @@ module OpenTox end def create service_uri, subjectid=nil + bnode = RDF::Node.new + klass = "RDF::OT."+self.class.to_s.split('::').last + #puts self.class + #puts klass + #object = eval "#{~ + @rdf << [bnode, RDF.type, klass] #uri = File.join(service_uri,SecureRandom.uuid) - uri = RestClientWrapper.post(service_uri, {}, {:accept => 'text/uri-list', :subjectid => subjectid}) + uri = RestClientWrapper.post(service_uri, self.to_ntriples, {:content_type => 'text/plain', :accept => 'text/uri-list', :subjectid => subjectid}) + #uri = RestClientWrapper.put(uri, {}, {:accept => 'text/uri-list', :subjectid => subjectid}) URI.task?(service_uri) ? from_uri(uri, subjectid, false) : from_uri(uri, subjectid) end diff --git a/lib/overwrite.rb b/lib/overwrite.rb index d98769e..fa2128a 100644 --- a/lib/overwrite.rb +++ b/lib/overwrite.rb @@ -1,3 +1,23 @@ +class Object + # An object is blank if it's false, empty, or a whitespace string. + # For example, "", " ", +nil+, [], and {} are all blank. + def blank? + respond_to?(:empty?) ? empty? : !self + end + + def numeric? + true if Float(self) rescue false + end +end + +=begin +module Enumerable + def duplicates + inject({}) {|h,v| h[v] += 1; h}.reject{|k,v| v==1}.keys + end +end +=end + class String def underscore self.gsub(/::/, '/'). -- cgit v1.2.3