Last active
August 29, 2015 14:27
-
-
Save reggieb/cb3e2289e31a1952b045 to your computer and use it in GitHub Desktop.
Used in combination with FedoraMigrate to idenitfy target Model Class if not obvious from Object Content Model. https://github.com/projecthydra-labs/fedora-migrate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ClassFinder | |
| attr_reader :pid | |
| def initialize(pid) | |
| @pid = pid | |
| end | |
| def object | |
| @object ||= self.class.source_objects.select{|x| x.pid =~ /#{pid}/}.first | |
| end | |
| def self.repository_migrator | |
| @repository_migrator ||= FedoraMigrate::RepositoryMigrator.new | |
| end | |
| def self.source_objects | |
| @source_objects ||= repository_migrator.source_objects | |
| end | |
| def rels_ext | |
| pair = object.datastreams.find{|x| x.last.dsid === 'RELS-EXT'} | |
| pair.last if pair | |
| end | |
| def rel_ext_xml | |
| return unless rels_ext | |
| Nokogiri::XML(rels_ext.content) | |
| end | |
| def rdf_resource | |
| return unless rel_ext_xml | |
| rel_ext_xml.xpath("//rel:isMemberOf/@rdf:resource").select(&:present?).first | |
| end | |
| def rdf_resource_value | |
| return unless rdf_resource | |
| @rdf_resource_value ||= rdf_resource.value | |
| end | |
| def rdf_resource_name | |
| rdf_resource_value ? rdf_resource_value.split(':').last : pid | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment