Sha256: 04909ca482dfae815994719dc33cca427e3a1ff2b497a1fdc526d81b669bd6e6

Contents?: true

Size: 1.6 KB

Versions: 11

Compression:

Stored size: 1.6 KB

Contents

module ActiveFedora
  module RdfNode
    class TermProxy

      attr_reader :graph, :subject, :predicate, :options
      delegate :class, :to_s, :==, :kind_of?, :each, :map, :empty?, :as_json, :is_a?, :to => :values

      # @param graph RDF::Graph
      # @param subject RDF::URI
      # @param options Hash
      def initialize(graph, subject, predicate, options)
        @graph = graph
        @subject = subject
        @predicate = predicate
        @options = options
      end

      def build
        new_subject = RDF::Node.new
        graph.graph.insert([subject, predicate, new_subject])
        graph.target_class(predicate).new(graph.graph, new_subject)
      end

      def <<(*values)
        values.each { |value| graph.append(subject, predicate, value) }
        values
      end

      def delete(*values)
        values.each do |value| 
          graph.delete_predicate(subject, predicate, value)
        end

        values
      end

      def values
        values = []

        graph.query(subject, predicate).each do |solution|
          v = solution.value
          v = v.to_s if v.is_a? RDF::Literal
          if options[:type] == :date
            v = Date.parse(v)
          end
          values << v
        end
        if options[:class_name]
          values = values.map{ |found_subject| graph.target_class(predicate).new(graph.graph, found_subject)}
        end
        
        values
      end
      
      def method_missing(method, *args, &block)
        if values.respond_to? method
          values.send(method, *args, &block)
        else
          super
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-6.0.0.pre7 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-5.5.2 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre6 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre5 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre4 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre3 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre2 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-5.5.1 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-6.0.0.pre1 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-5.5.0 lib/active_fedora/rdf_node/term_proxy.rb
active-fedora-5.5.0.rc2 lib/active_fedora/rdf_node/term_proxy.rb