Class: Hydra::Datastream::ModsBasic

Inherits:
ActiveFedora::NokogiriDatastream
  • Object
show all
Includes:
CommonModsIndexMethods
Defined in:
app/models/hydra/datastream/mods_basic.rb

Constant Summary collapse

MODS_NS =

MODS XML constants.

'http://www.loc.gov/mods/v3'
MODS_SCHEMA =
'http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonModsIndexMethods

#extract_person_full_names, #extract_person_organizations

Class Method Details

.conference_relator_termsObject

FIXME: this should move to mods behavior module and/or mods gem ? these are a selected subset from id.loc.gov/vocabulary/relators.html



218
219
220
221
# File 'app/models/hydra/datastream/mods_basic.rb', line 218

def self.conference_relator_terms
  {"hst" => "Host"
  }
end

.conference_templateObject

Generates a new :conference node Uses mods:name



174
175
176
177
178
179
180
181
182
183
184
# File 'app/models/hydra/datastream/mods_basic.rb', line 174

def self.conference_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.name(:type=>"conference") {
      xml.namePart
      xml.role {
        xml.roleTerm(:authority=>"marcrelator", :type=>"text")
      }                          
    }
  end
  return builder.doc.root
end

.organization_relator_termsObject

FIXME: this should move to mods behavior module and/or mods gem ? these are a selected subset from id.loc.gov/vocabulary/relators.html



225
226
227
228
229
# File 'app/models/hydra/datastream/mods_basic.rb', line 225

def self.organization_relator_terms
  {"fnd" => "Funder",
   "hst" => "Host"
  }
end

.organization_templateObject

Generates a new :organization node Uses mods:name



160
161
162
163
164
165
166
167
168
169
170
# File 'app/models/hydra/datastream/mods_basic.rb', line 160

def self.organization_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.name(:type=>"corporate") {
      xml.namePart
      xml.role {
        xml.roleTerm(:authority=>"marcrelator", :type=>"text")
      }                          
    }
  end
  return builder.doc.root
end

.person_relator_termsObject

FIXME: this should move to mods behavior module and/or mods gem ? these are a selected subset from id.loc.gov/vocabulary/relators.html



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'app/models/hydra/datastream/mods_basic.rb', line 201

def self.person_relator_terms
  {"aut" => "Author",
   "clb" => "Collaborator",
   "com" => "Compiler",
   "cre" => "Creator",
   "ctb" => "Contributor",
   "edt" => "Editor",
   "ill" => "Illustrator",
   "res" => "Researcher",
   "rth" => "Research team head",
   "rtm" => "Research team member",
   "trl" => "Translator"
   }
end

.person_templateObject

Generates a new :person node Uses mods:name



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/models/hydra/datastream/mods_basic.rb', line 144

def self.person_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.name(:type=>"personal") {
      xml.namePart(:type=>"family")
      xml.namePart(:type=>"given")
      xml.affiliation
      xml.role {
        xml.roleTerm(:type=>"text")
      }
    }
  end
  return builder.doc.root
end

.xml_templateObject

Generates an empty Mods Generic Content (used when you call ModsGenericContent.new without passing in existing xml) this is necessary to create new objects



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/hydra/datastream/mods_basic.rb', line 63

def self.xml_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.mods(:version=>"3.4", "xmlns:xlink"=>"http://www.w3.org/1999/xlink",
       "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
       "xmlns"=>MODS_NS,
       "xsi:schemaLocation"=>"#{MODS_NS} #{MODS_SCHEMA}") {
      xml.titleInfo(:lang=>"") {
        xml.title
      }
      xml.name(:type=>"personal") {
        xml.namePart(:type=>"given")
        xml.namePart(:type=>"family")
        xml.role {
          xml.roleTerm(:authority=>"marcrelator", :type=>"text")
        }
      }
      xml.abstract
      xml.identifier(:type=>"uri")
      xml.subject {
        xml.topic
      }
    }
  end
  return builder.doc
end

Instance Method Details

#insert_conferenceObject

create a new :conference node in the xml



100
101
102
# File 'app/models/hydra/datastream/mods_basic.rb', line 100

def insert_conference
  insert_new_node(:conference)
end

#insert_new_node(term) ⇒ Object

FIXME: this method should probably get pushed down to OM Create a new node and insert it into the document after existing term nodes, or as a child of root if no such term nodes exist PREREQ: term_template method must exist and should return node ready for insertion into DOM

Parameters:

  • term

    the symbol for an OM term with a corresponding _template method



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/hydra/datastream/mods_basic.rb', line 109

def insert_new_node(term)
  node = self.class.send("#{term.to_s}_template")
  nodeset = self.find_by_terms(term)

  unless nodeset.nil?
    if nodeset.empty?
      self.ng_xml.root.add_child(node)
      index = 0
    else
      nodeset.after(node)
      index = nodeset.length
    end
    self.dirty = true
  end
  return node, index
end

#insert_organizationObject

create a new :organization node in the xml



95
96
97
# File 'app/models/hydra/datastream/mods_basic.rb', line 95

def insert_organization
  insert_new_node(:organization)
end

#insert_personObject

create a new :person node in the xml



90
91
92
# File 'app/models/hydra/datastream/mods_basic.rb', line 90

def insert_person
  insert_new_node(:person)
end

#remove_node(term, index) ⇒ Object

FIXME: this method should probably get pushed down to OM

a model might have a wrapping method like  remove_organization

Remove the node identified by the OM term and index

Parameters:

  • term

    the OM term to be removed

  • index

    the index of the OM term (e.g. the 2nd :person node)



131
132
133
134
135
136
137
# File 'app/models/hydra/datastream/mods_basic.rb', line 131

def remove_node(term, index)
  node = self.find_by_terms(term.to_sym => index.to_i).first
  unless node.nil?
    node.remove
    self.dirty = true
  end
end

#to_solr(solr_doc = Hash.new) ⇒ Object

override OM method for (FIXME: why?) some reason



188
189
190
191
192
193
194
# File 'app/models/hydra/datastream/mods_basic.rb', line 188

def to_solr(solr_doc=Hash.new)
  super(solr_doc)
  solr_doc.merge!(extract_person_full_names)
  solr_doc.merge!(extract_person_organizations)
  solr_doc.merge!(:object_type_facet => "Generic Mods content")
  solr_doc
end