Class: ActiveFedora::RelsExtDatastream

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/utils/predicate_patch.rb

Class Method Summary collapse

Class Method Details

.short_predicate(predicate) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dor/utils/predicate_patch.rb', line 6

def self.short_predicate(predicate)
  # for this regex to short-circuit correctly, namespaces must be sorted into descending order by length
  if match = /^(#{Predicates.predicate_mappings.keys.sort.reverse.join('|')})(.+)$/.match(predicate.to_str)
    namespace = match[1]
    predicate = match[2]
    ns_mapping = Predicates.predicate_mappings[namespace] ||= {}
    pred = ns_mapping.invert[predicate]
    if pred.nil?
      pred = predicate.underscore.to_sym
      ns_mapping[pred] = predicate
    end
    pred
  else
    raise "Unable to parse predicate: #{predicate}"
  end
end