Module: ActiveFedora::SemanticNode::ClassMethods

Defined in:
lib/active_fedora/semantic_node.rb

Instance Method Summary collapse

Instance Method Details

#internal_uri(pid) ⇒ String

Returns a URI represented as a string.

Parameters:

  • pid (String)

    the fedora object identifier

Returns:

  • (String)

    a URI represented as a string



164
165
166
# File 'lib/active_fedora/semantic_node.rb', line 164

def internal_uri(pid)
  "info:fedora/#{pid}"
end

#pid_from_uri(uri) ⇒ String

Returns the pid component of the URI.

Parameters:

  • uri (String)

    a uri (as a string)

Returns:

  • (String)

    the pid component of the URI



170
171
172
# File 'lib/active_fedora/semantic_node.rb', line 170

def pid_from_uri(uri)
  uri.gsub("info:fedora/", "")
end

#pids_from_uris(uris) ⇒ String

Returns the pid component of the URI.

Parameters:

  • uris (String, Array)

    a single uri (as a string) or a list of uris to convert to pids

Returns:

  • (String)

    the pid component of the URI



137
138
139
140
141
142
143
144
# File 'lib/active_fedora/semantic_node.rb', line 137

def pids_from_uris(uris) 
  Deprecation.warn(SemanticNode, "pids_from_uris has been deprecated and will be removed in active-fedora 8.0.0", caller)
  if uris.kind_of? String
    pid_from_uri(uris)
  else
    Array(uris).map {|uri| pid_from_uri(uri)}
  end
end

#to_class_uri(attrs = {}) ⇒ Object

Returns a suitable uri object for :has_model Should reverse Model#from_class_uri



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/active_fedora/semantic_node.rb', line 148

def to_class_uri(attrs = {})
  if self.respond_to? :pid_suffix
    pid_suffix = self.pid_suffix
  else
    pid_suffix = attrs.fetch(:pid_suffix, ContentModel::CMODEL_PID_SUFFIX)
  end
  if self.respond_to? :pid_namespace
    namespace = self.pid_namespace
  else
    namespace = attrs.fetch(:namespace, ContentModel::CMODEL_NAMESPACE)
  end
  "info:fedora/#{namespace}:#{ContentModel.sanitized_class_name(self)}#{pid_suffix}" 
end