Class: ActiveFedora::RDFDatastream::TermProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/rdf_datastream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, subject, predicate) ⇒ TermProxy

Returns a new instance of TermProxy.



116
117
118
119
120
121
# File 'lib/active_fedora/rdf_datastream.rb', line 116

def initialize(graph, subject, predicate)
  @graph = graph

  @subject = subject
  @predicate = predicate
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/active_fedora/rdf_datastream.rb', line 148

def method_missing(method, *args, &block)

  if values.respond_to? method
    values.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#graphObject (readonly)

Returns the value of attribute graph.



113
114
115
# File 'lib/active_fedora/rdf_datastream.rb', line 113

def graph
  @graph
end

#predicateObject (readonly)

Returns the value of attribute predicate.



113
114
115
# File 'lib/active_fedora/rdf_datastream.rb', line 113

def predicate
  @predicate
end

#subjectObject (readonly)

Returns the value of attribute subject.



113
114
115
# File 'lib/active_fedora/rdf_datastream.rb', line 113

def subject
  @subject
end

Instance Method Details

#<<(*values) ⇒ Object



123
124
125
126
# File 'lib/active_fedora/rdf_datastream.rb', line 123

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

#delete(*values) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/active_fedora/rdf_datastream.rb', line 128

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

  values
end

#valuesObject



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/active_fedora/rdf_datastream.rb', line 136

def values
  values = []

  graph.query(subject, predicate).each do |solution|
    v = solution.value
    v = v.to_s if v.is_a? RDF::Literal
    values << v
  end

  values
end