bplmodels 0.0.91

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +0 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/bplmodels/application.js +15 -0
  6. data/app/assets/stylesheets/bplmodels/application.css +13 -0
  7. data/app/controllers/bplmodels/application_controller.rb +4 -0
  8. data/app/helpers/bplmodels/application_helper.rb +4 -0
  9. data/app/models/bplmodels/audio_file.rb +14 -0
  10. data/app/models/bplmodels/book.rb +35 -0
  11. data/app/models/bplmodels/card.rb +35 -0
  12. data/app/models/bplmodels/characterization.rb +92 -0
  13. data/app/models/bplmodels/collection.rb +118 -0
  14. data/app/models/bplmodels/complex_object_base.rb +24 -0
  15. data/app/models/bplmodels/correspondence.rb +35 -0
  16. data/app/models/bplmodels/document.rb +35 -0
  17. data/app/models/bplmodels/document_file.rb +8 -0
  18. data/app/models/bplmodels/ephemera.rb +35 -0
  19. data/app/models/bplmodels/file.rb +151 -0
  20. data/app/models/bplmodels/file_content_datastream.rb +10 -0
  21. data/app/models/bplmodels/fits_datastream.rb +190 -0
  22. data/app/models/bplmodels/image.rb +14 -0
  23. data/app/models/bplmodels/image_file.rb +18 -0
  24. data/app/models/bplmodels/institution.rb +159 -0
  25. data/app/models/bplmodels/manuscript.rb +34 -0
  26. data/app/models/bplmodels/map.rb +34 -0
  27. data/app/models/bplmodels/mods_desc_metadata.rb +1826 -0
  28. data/app/models/bplmodels/musical_notation.rb +34 -0
  29. data/app/models/bplmodels/newspaper.rb +15 -0
  30. data/app/models/bplmodels/nom_terminology.rb +1242 -0
  31. data/app/models/bplmodels/non_photographic_print.rb +34 -0
  32. data/app/models/bplmodels/oai_collection.rb +19 -0
  33. data/app/models/bplmodels/oai_metadata.rb +75 -0
  34. data/app/models/bplmodels/oai_object.rb +45 -0
  35. data/app/models/bplmodels/object.rb +36 -0
  36. data/app/models/bplmodels/object_base.rb +1241 -0
  37. data/app/models/bplmodels/objects/collection.rb~ +28 -0
  38. data/app/models/bplmodels/objects/image.rb~ +59 -0
  39. data/app/models/bplmodels/objects/postcard.rb~ +56 -0
  40. data/app/models/bplmodels/organizational_set.rb +25 -0
  41. data/app/models/bplmodels/periodical.rb +37 -0
  42. data/app/models/bplmodels/photographic_print.rb +34 -0
  43. data/app/models/bplmodels/relation_base.rb +99 -0
  44. data/app/models/bplmodels/scrapbook.rb +35 -0
  45. data/app/models/bplmodels/simple_object_base.rb +27 -0
  46. data/app/models/bplmodels/sound_recording.rb +15 -0
  47. data/app/models/bplmodels/system_collection.rb +8 -0
  48. data/app/models/bplmodels/uploads_set.rb +3 -0
  49. data/app/models/bplmodels/workflow_metadata.rb +99 -0
  50. data/app/views/layouts/bplmodels/application.html.erb +14 -0
  51. data/config/application.rb +6 -0
  52. data/config/predicate_mappings.yml +61 -0
  53. data/config/routes.rb +2 -0
  54. data/lib/bplmodels.rb +21 -0
  55. data/lib/bplmodels/constants.rb +119 -0
  56. data/lib/bplmodels/datastream_input_funcs.rb +949 -0
  57. data/lib/bplmodels/engine.rb +5 -0
  58. data/lib/bplmodels/engine.rb~ +5 -0
  59. data/lib/bplmodels/finder.rb +192 -0
  60. data/lib/bplmodels/object_funcs.rb +10 -0
  61. data/lib/bplmodels/version.rb +3 -0
  62. data/lib/tasks/bplmodels_tasks.rake +4 -0
  63. data/test/bplmodels_test.rb +7 -0
  64. data/test/dummy/README.rdoc +261 -0
  65. data/test/dummy/Rakefile +7 -0
  66. data/test/dummy/app/assets/javascripts/application.js +15 -0
  67. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  68. data/test/dummy/app/controllers/application_controller.rb +3 -0
  69. data/test/dummy/app/helpers/application_helper.rb +2 -0
  70. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/test/dummy/config.ru +4 -0
  72. data/test/dummy/config/application.rb +59 -0
  73. data/test/dummy/config/boot.rb +10 -0
  74. data/test/dummy/config/environment.rb +5 -0
  75. data/test/dummy/config/environments/development.rb +37 -0
  76. data/test/dummy/config/environments/production.rb +67 -0
  77. data/test/dummy/config/environments/test.rb +37 -0
  78. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/test/dummy/config/initializers/inflections.rb +15 -0
  80. data/test/dummy/config/initializers/mime_types.rb +5 -0
  81. data/test/dummy/config/initializers/secret_token.rb +7 -0
  82. data/test/dummy/config/initializers/session_store.rb +8 -0
  83. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  84. data/test/dummy/config/locales/en.yml +5 -0
  85. data/test/dummy/config/routes.rb +4 -0
  86. data/test/dummy/public/404.html +26 -0
  87. data/test/dummy/public/422.html +26 -0
  88. data/test/dummy/public/500.html +25 -0
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/dummy/script/rails +6 -0
  91. data/test/integration/navigation_test.rb +10 -0
  92. data/test/test_helper.rb +15 -0
  93. metadata +234 -0
@@ -0,0 +1,14 @@
1
+ module Bplmodels
2
+ class Image < Bplmodels::SimpleObjectBase
3
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
4
+
5
+ belongs_to :institution, :class_name => 'Bplmodels::Institution', :property => :is_member_of
6
+
7
+ has_and_belongs_to_many :image_files, :class_name => "Bplmodels::ImageFile", :property=> :has_image
8
+
9
+ def fedora_name
10
+ 'image'
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ module Bplmodels
2
+ class ImageFile < Bplmodels::File
3
+
4
+ has_many :next_image, :class_name => "Bplmodels::ImageFile", :property=> :is_preceding_image_of
5
+
6
+ has_many :prev_image, :class_name => "Bplmodels::ImageFile", :property=> :is_following_image_of
7
+
8
+ # Use a callback method to declare which derivatives you want
9
+ makes_derivatives :generate_derivatives
10
+
11
+ def fedora_name
12
+ 'image_file'
13
+ end
14
+
15
+
16
+
17
+ end
18
+ end
@@ -0,0 +1,159 @@
1
+ module Bplmodels
2
+ class Institution < Bplmodels::RelationBase
3
+
4
+ has_many :collections, :class_name=> "Bplmodels::Collection", :property=> :is_member_of
5
+
6
+ has_metadata :name => "workflowMetadata", :type => WorkflowMetadata
7
+
8
+ #A collection can have another collection as a member, or an image
9
+ def insert_member(fedora_object)
10
+ if (fedora_object.instance_of?(Bplmodels::Collection))
11
+
12
+ #add to the members ds
13
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
14
+
15
+ #add to the rels-ext ds
16
+ fedora_object.institutions << selfinstitutioninstitution
17
+ self.collections << fedora_object
18
+
19
+ end
20
+
21
+ fedora_object.save!
22
+ self.save!
23
+
24
+ end
25
+
26
+ def fedora_name
27
+ 'institution'
28
+ end
29
+
30
+ def to_solr(doc = {} )
31
+ doc = super(doc)
32
+
33
+ # description
34
+ doc['abstract_tsim'] = self.descMetadata.abstract
35
+
36
+ # url
37
+ doc['institution_url_ss'] = self.descMetadata.local_other
38
+
39
+ # sublocations
40
+ doc['sub_location_ssim'] = self.descMetadata.item_location.holding_simple.copy_information.sub_location
41
+
42
+ # hierarchical geo
43
+ country = self.descMetadata.subject.hierarchical_geographic.country
44
+ state = self.descMetadata.subject.hierarchical_geographic.state
45
+ county = self.descMetadata.subject.hierarchical_geographic.county
46
+ city = self.descMetadata.subject.hierarchical_geographic.city
47
+ city_section = self.descMetadata.subject.hierarchical_geographic.city_section
48
+
49
+ doc['subject_geo_country_ssim'] = country
50
+ doc['subject_geo_state_ssim'] = state
51
+ doc['subject_geo_county_ssim'] = county
52
+ doc['subject_geo_city_ssim'] = city
53
+ doc['subject_geo_citysection_ssim'] = city_section
54
+
55
+ # add " (county)" to county values for better faceting
56
+ county_facet = []
57
+ if county.length > 0
58
+ county.each do |county_value|
59
+ county_facet << county_value + ' (county)'
60
+ end
61
+ end
62
+
63
+ # add hierarchical geo to subject-geo text field
64
+ doc['subject_geographic_tsim'] = country + state + county + city + city_section
65
+
66
+ # add hierarchical geo to subject-geo facet field
67
+ doc['subject_geographic_ssim'] = country + state + county_facet + city + city_section
68
+
69
+ # coordinates
70
+ coords = self.descMetadata.subject.cartographics.coordinates
71
+ doc['subject_coordinates_geospatial'] = coords
72
+ doc['subject_point_geospatial'] = coords
73
+
74
+ # TODO: DRY this out with Bplmodels::ObjectBase
75
+ # geographic data as GeoJSON
76
+ # subject_geojson_facet_ssim = for map-based faceting + display
77
+ # subject_hiergeo_geojson_ssm = for display of hiergeo metadata
78
+ doc['subject_geojson_facet_ssim'] = []
79
+ doc['subject_hiergeo_geojson_ssm'] = []
80
+ 0.upto self.descMetadata.subject.length-1 do |subject_index|
81
+
82
+ this_subject = self.descMetadata.mods(0).subject(subject_index)
83
+
84
+ # TGN-id-derived geo subjects. assumes only longlat points, no bboxes
85
+ if this_subject.cartographics.coordinates.any? && this_subject.hierarchical_geographic.any?
86
+ geojson_hash_base = {type: 'Feature', geometry: {type: 'Point'}}
87
+ # get the coordinates
88
+ coords = coords[0]
89
+ if coords.match(/^[-]?[\d]*[\.]?[\d]*,[-]?[\d]*[\.]?[\d]*$/)
90
+ geojson_hash_base[:geometry][:coordinates] = coords.split(',').reverse.map { |v| v.to_f }
91
+ end
92
+
93
+ facet_geojson_hash = geojson_hash_base.dup
94
+ hiergeo_geojson_hash = geojson_hash_base.dup
95
+
96
+ # get the hierGeo elements, except 'continent'
97
+ hiergeo_hash = {}
98
+ ModsDescMetadata.terminology.retrieve_node(:subject,:hierarchical_geographic).children.each do |hgterm|
99
+ hiergeo_hash[hgterm[0]] = '' unless hgterm[0].to_s == 'continent'
100
+ end
101
+ hiergeo_hash.each_key do |k|
102
+ hiergeo_hash[k] = this_subject.hierarchical_geographic.send(k)[0].presence
103
+ end
104
+ hiergeo_hash.reject! {|k,v| !v } # remove any nil values
105
+
106
+ hiergeo_hash[:other] = this_subject.geographic[0] if this_subject.geographic[0]
107
+
108
+ hiergeo_geojson_hash[:properties] = hiergeo_hash
109
+ facet_geojson_hash[:properties] = {placename: DatastreamInputFuncs.render_display_placename(hiergeo_hash)}
110
+
111
+ if geojson_hash_base[:geometry][:coordinates].is_a?(Array)
112
+ doc['subject_hiergeo_geojson_ssm'].append(hiergeo_geojson_hash.to_json)
113
+ doc['subject_geojson_facet_ssim'].append(facet_geojson_hash.to_json)
114
+ end
115
+ end
116
+ end
117
+
118
+ doc['institution_pid_si'] = self.pid
119
+ doc['institution_pid_ssi'] = self.pid
120
+
121
+
122
+ doc
123
+
124
+ end
125
+
126
+ #Expects the following args:
127
+ #parent_pid => id of the parent object
128
+ #local_id => local ID of the object
129
+ #local_id_type => type of that local ID
130
+ #label => label of the collection
131
+ def self.mint(args)
132
+
133
+ args[:namespace_id] ||= ARK_CONFIG_GLOBAL['namespace_commonwealth_pid']
134
+
135
+ #TODO: Duplication check here to prevent over-writes?
136
+
137
+ response = Typhoeus::Request.post(ARK_CONFIG_GLOBAL['url'] + "/arks.json", :params => {:ark=>{:namespace_ark => ARK_CONFIG_GLOBAL['namespace_commonwealth_ark'], :namespace_id=>ARK_CONFIG_GLOBAL['namespace_commonwealth_pid'], :url_base => ARK_CONFIG_GLOBAL['ark_commonwealth_base'], :model_type => self.name, :local_original_identifier=>args[:local_id], :local_original_identifier_type=>args[:local_id_type]}})
138
+ as_json = JSON.parse(response.body)
139
+
140
+ Bplmodels::Institution.find_in_batches('id'=>as_json["pid"]) do |group|
141
+ group.each { |solr_result|
142
+ return as_json["pid"]
143
+ }
144
+ end
145
+
146
+ object = self.new(:pid=>as_json["pid"])
147
+
148
+ title = Bplmodels::DatastreamInputFuncs.getProperTitle(args[:label])
149
+ object.label = args[:label]
150
+ object.descMetadata.insert_title(title[0], title[1])
151
+
152
+ object.read_groups = ["public"]
153
+ object.edit_groups = ["superuser", 'admin[' + object.pid + ']']
154
+
155
+ return object
156
+ end
157
+
158
+ end
159
+ end
@@ -0,0 +1,34 @@
1
+ module Bplmodels
2
+ class Manuscript < Bplmodels::ComplexObjectBase
3
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
4
+
5
+
6
+ #A collection can have another collection as a member, or an image
7
+ def insert_member(fedora_object)
8
+ if (fedora_object.instance_of?(Bplmodels::ImageFile))
9
+
10
+ #add to the members ds
11
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
12
+
13
+ #add to the rels-ext ds
14
+ fedora_object.object << self
15
+ self.image_files << fedora_object
16
+
17
+ end
18
+
19
+ fedora_object.save!
20
+ self.save!
21
+
22
+ end
23
+
24
+ def to_solr(doc = {} )
25
+ doc = super(doc)
26
+ doc['active_fedora_model_ssi'] = self.class.name
27
+ doc
28
+ end
29
+
30
+ def fedora_name
31
+ 'manuscript'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Bplmodels
2
+ class Map < Bplmodels::SimpleObjectBase
3
+ #has_file_datastream :name => 'productionMaster', :type => ActiveFedora::Datastream
4
+
5
+
6
+ #A collection can have another collection as a member, or an image
7
+ def insert_member(fedora_object)
8
+ if (fedora_object.instance_of?(Bplmodels::ImageFile))
9
+
10
+ #add to the members ds
11
+ members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name)
12
+
13
+ #add to the rels-ext ds
14
+ fedora_object.object << self
15
+ self.image_files << fedora_object
16
+
17
+ end
18
+
19
+ fedora_object.save!
20
+ self.save!
21
+
22
+ end
23
+
24
+ def to_solr(doc = {} )
25
+ doc = super(doc)
26
+ doc['active_fedora_model_ssi'] = self.class.name
27
+ doc
28
+ end
29
+
30
+ def fedora_name
31
+ 'map'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,1826 @@
1
+ #encoding: utf-8
2
+ require 'mods'
3
+
4
+ module Bplmodels
5
+ class ModsDescMetadata < ActiveFedora::OmDatastream
6
+ #include Hydra::Datastream::CommonModsIndexMethods
7
+ # MODS XML constants.
8
+
9
+ def self.default_attributes
10
+ super.merge(:mimeType => 'application/xml')
11
+ end
12
+
13
+ MODS_NS = 'http://www.loc.gov/mods/v3'
14
+ MODS_SCHEMA = 'http://www.loc.gov/standards/mods/v3/mods-3-5.xsd'
15
+ MODS_PARAMS = {
16
+ "version" => "3.5",
17
+ "xmlns:xlink" => "http://www.w3.org/1999/xlink",
18
+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
19
+ #"xmlns" => MODS_NS,
20
+ "xsi:schemaLocation" => "#{MODS_NS} #{MODS_SCHEMA}",
21
+ "xmlns:mods" => "http://www.loc.gov/mods/v3"
22
+ }
23
+
24
+ # OM terminology.
25
+
26
+ set_terminology do |t|
27
+ indexer = Solrizer::Descriptor.new(:string, :indexed, :stored, :searchable)
28
+ indexer_single = Solrizer::Descriptor.new(:text, :indexed, :stored, :searchable)
29
+ indexer_multiple = Solrizer::Descriptor.new(:text, :indexed, :stored, :searchable, :multivalued)
30
+
31
+ t.root :path => 'mods', :xmlns => MODS_NS
32
+ t.originInfo do
33
+ t.dateOther
34
+ end
35
+ #t.abstract(:path=>"abstract", :index_as=>[indexer_single])
36
+
37
+ # ABSTRACT -------------------------------------------------------------------------------
38
+ #t.abstract(:path=>"mods/oxns:abstract") {
39
+ t.abstract(:path=>"abstract") {
40
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
41
+ t.type_at :path=>{:attribute=>"type"}
42
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
43
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
44
+ }
45
+ }
46
+
47
+ # GENRE ----------------------------------------------------------------------------------
48
+ t.genre(:path => 'genre') {
49
+ t.displayLabel :path => {:attribute=>'displayLabel'}
50
+ t.type_at :path=>{:attribute=>"type"}
51
+ t.usage :path=>{:attribute=>'usage'}
52
+ ::Mods::AUTHORITY_ATTRIBS.each { |attr_name|
53
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
54
+ }
55
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
56
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
57
+ }
58
+ }
59
+
60
+ # IDENTIIER ------------------------------------------------------------------------------
61
+ t.identifier(:path => 'identifier') {
62
+ #t.identifier(:path=>"identifier[not(@type=uri)]")
63
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
64
+ t.invalid :path=>{:attribute=>'invalid'}
65
+ t.type_at :path=>{:attribute=>'type'}
66
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
67
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
68
+ }
69
+ }
70
+
71
+ # ACCESS_CONDITION -----------------------------------------------------------------------
72
+ t.accessCondition(:path => 'accessCondition') {
73
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
74
+ t.type_at :path=>{:attribute=>"type"}
75
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
76
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
77
+ }
78
+ }
79
+
80
+ =begin
81
+ # CLASSIFICATION -------------------------------------------------------------------------
82
+ t.classification(:path => 'mods/oxns:classification') {
83
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
84
+ t.edition :path =>{:attribute=>"edition"}
85
+ ::Mods::AUTHORITY_ATTRIBS.each { |attr_name|
86
+ t.send attr_name, :path => {:attribute=>"#{attr_name}"}
87
+ }
88
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
89
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
90
+ }
91
+ }
92
+
93
+
94
+ # EXTENSION ------------------------------------------------------------------------------
95
+ t.extension(:path => 'mods/oxns:extension') {
96
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
97
+ }
98
+
99
+ # LANGUAGE -------------------------------------------------------------------------------
100
+ t.language(:path => 'mods/oxns:language') {
101
+ # attributes
102
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
103
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
104
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
105
+ }
106
+ # child elements
107
+ t.languageTerm :path => 'languageTerm'
108
+ t.code_term :path => 'languageTerm', :attributes => { :type => "code" }
109
+ t.text_term :path => 'languageTerm', :attributes => { :type => "text" }
110
+ t.scriptTerm :path => 'scriptTerm'
111
+ }
112
+ t.languageTerm(:path => 'languageTerm') {
113
+ t.type_at :path=>{:attribute=>'type'}
114
+ ::Mods::AUTHORITY_ATTRIBS.each { |attr_name|
115
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
116
+ }
117
+ } # t.language
118
+
119
+ # LOCATION -------------------------------------------------------------------------------
120
+ t.location(:path => 'mods/oxns:location') {
121
+ # attributes
122
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
123
+ ::Mods::LANG_ATTRIBS.each { |attr_name|
124
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
125
+ }
126
+ # child elements
127
+ t.physicalLocation(:path => 'physicalLocation') {
128
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
129
+ ::Mods::AUTHORITY_ATTRIBS.each { |attr_name|
130
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
131
+ }
132
+ }
133
+ t.shelfLocator :path => 'shelfLocator'
134
+ t.url(:path => 'url') {
135
+ t.dateLastAccessed :path=>{:attribute=>'dateLastAccessed'}
136
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
137
+ t.note :path=>{:attribute=>'note'}
138
+ t.access :path=>{:attribute=>'access'}
139
+ t.usage :path=>{:attribute=>'usage'}
140
+ }
141
+ t.holdingSimple :path => 'holdingSimple'
142
+ t.holdingExternal :path => 'holdingExternal'
143
+ } # t.location
144
+
145
+ :path => 'languageTerm', :attributes => { :type => "text" }
146
+ # NAME ------------------------------------------------------------------------------------
147
+ t.plain_name(:path => 'mods/oxns:name') {
148
+ ::Mods::Name::ATTRIBUTES.each { |attr_name|
149
+ if attr_name != 'type'
150
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
151
+ else
152
+ t.type_at :path =>{:attribute=>"#{attr_name}"}
153
+ end
154
+ }
155
+ # elements
156
+ t.namePart(:path => 'namePart') {
157
+ t.type_at :path =>{:attribute=>"type"}
158
+ }
159
+ t.family_name :path => 'namePart', :attributes => {:type=>"family"}
160
+ t.given_name :path => 'namePart', :attributes => {:type=>"given"}
161
+ t.termsOfAddress :path => 'namePart', :attributes => {:type=>"termsOfAddress"}
162
+ t.date :path => 'namePart', :attributes => {:type=>"date"}
163
+
164
+ t.displayForm :path => 'displayForm'
165
+ t.affiliation :path => 'affiliation'
166
+ t.description_el :path => 'description' # description is used by Nokogiri
167
+ t.role(:path => 'role') {
168
+ t.roleTerm(:path => 'roleTerm') {
169
+ t.type_at :path =>{:attribute=> "type"}
170
+ ::Mods::AUTHORITY_ATTRIBS.each { |attr_name|
171
+ t.send attr_name, :path =>{:attribute=>"#{attr_name}"}
172
+ }
173
+ }
174
+ # FIXME - not sure how to do this stuff
175
+ # role convenience method
176
+ t.authority :path => '.', :accessor => lambda { |role_node|
177
+ a = nil
178
+ role_node.roleTerm.each { |role_t|
179
+ # role_t.authority will be [] if it is missing from an earlier roleTerm
180
+ if role_t.authority && (!a || a.size == 0)
181
+ a = role_t.authority
182
+ end
183
+ }
184
+ a
185
+ }
186
+ # role convenience method
187
+ r.code :path => '.', :accessor => lambda { |role_node|
188
+ c = nil
189
+ role_node.roleTerm.each { |role_t|
190
+ if role_t.type_at == 'code'
191
+ c ||= role_t.text
192
+ end
193
+ }
194
+ c
195
+ }
196
+ # role convenience method
197
+ r.value :path => '.', :accessor => lambda { |role_node|
198
+ val = nil
199
+ role_node.roleTerm.each { |role_t|
200
+ if role_t.type_at == 'text'
201
+ val ||= role_t.text
202
+ end
203
+ }
204
+ # FIXME: this is broken if there are multiple role codes and some of them are not marcrelator
205
+ if !val && role_node.code && role_node.authority.first =~ /marcrelator/
206
+ val = MARC_RELATOR[role_node.code.first]
207
+ end
208
+ val
209
+ }
210
+ } # role node
211
+ #END FIXME
212
+
213
+ # name convenience method
214
+ # uses the displayForm of a name if present
215
+ # if no displayForm, try to make a string from family, given and terms of address
216
+ # otherwise, return all non-date nameParts concatenated together
217
+ n.display_value :path => '.', :single => true, :accessor => lambda {|name_node|
218
+ dv = ''
219
+ if name_node.displayForm && name_node.displayForm.text.size > 0
220
+ dv = name_node.displayForm.text
221
+ end
222
+ if dv.blank?
223
+ if name_node.type_at == 'personal'
224
+ if name_node.family_name.size > 0
225
+ dv = name_node.given_name.size > 0 ? "#{name_node.family_name.text}, #{name_node.given_name.text}" : name_node.family_name.text
226
+ elsif name_node.given_name.size > 0
227
+ dv = name_node.given_name.text
228
+ end
229
+ if !dv.blank?
230
+ first = true
231
+ name_node.namePart.each { |np|
232
+ if np.type_at == 'termsOfAddress' && !np.text.blank?
233
+ if first
234
+ dv = dv + " " + np.text
235
+ first = false
236
+ else
237
+ dv = dv + ", " + np.text
238
+ end
239
+ end
240
+ }
241
+ else # no family or given name
242
+ dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.blank?}.join(" ")
243
+ end
244
+ else # not a personal name
245
+ dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.blank?}.join(" ")
246
+ end
247
+ end
248
+ dv.strip.blank? ? nil : dv.strip
249
+ }
250
+
251
+ # name convenience method
252
+ n.display_value_w_date :path => '.', :single => true, :accessor => lambda {|name_node|
253
+ dv = ''
254
+ dv = dv + name_node.display_value if name_node.display_value
255
+ name_node.namePart.each { |np|
256
+ if np.type_at == 'date' && !np.text.blank? && !dv.end_with?(np.text)
257
+ dv = dv + ", #{np.text}"
258
+ end
259
+ }
260
+ if dv.start_with?(', ')
261
+ dv.sub(', ', '')
262
+ end
263
+ dv.strip.blank? ? nil : dv.strip
264
+ }
265
+ } # t._plain_name
266
+
267
+ t.personal_name :path => '/m:mods/m:name[@type="personal"]'
268
+ t._personal_name :path => '//m:name[@type="personal"]'
269
+ t.corporate_name :path => '/m:mods/m:name[@type="corporate"]'
270
+ t._corporate_name :path => '//m:name[@type="corporate"]'
271
+ t.conference_name :path => '/m:mods/m:name[@type="conference"]'
272
+ t._conference_name :path => '//m:name[@type="conference"]'
273
+ =end
274
+
275
+
276
+
277
+
278
+
279
+
280
+ t.title_info(:path=>'titleInfo') {
281
+ t.usage(:path=>{:attribute=>"usage"})
282
+ t.display_label(:path=>{:attribute=>"displayLabel"})
283
+ t.nonSort(:path=>"nonSort", :index_as=>[:searchable, :displayable])
284
+ t.main_title(:path=>"title", :label=>"title")
285
+ t.language(:index_as=>[:facetable],:path=>{:attribute=>"lang"})
286
+ t.supplied(:path=>{:attribute=>"supplied"})
287
+ t.type(:path=>{:attribute=>"type"})
288
+ t.authority(:path=>{:attribute=>"authority"})
289
+ t.authorityURI(:path=>{:attribute=>"authorityURI"})
290
+ t.valueURI(:path=>{:attribute=>"valueURI"})
291
+ t.subtitle(:path=>"subTitle", :label=>"subtitle")
292
+ }
293
+ t.title(:proxy=>[:title_info, :main_title])
294
+
295
+ t.name(:path=>'name') {
296
+ # this is a namepart
297
+ t.usage(:path=>{:attribute=>"usage"})
298
+ t.namePart(:type=>:string, :label=>"generic name")
299
+ t.type(:path=>{:attribute=>"type"})
300
+ t.authority(:path=>{:attribute=>"authority"})
301
+ t.authorityURI(:path=>{:attribute=>"authorityURI"})
302
+ t.valueURI(:path=>{:attribute=>"valueURI"})
303
+
304
+ t.role(:ref=>[:role])
305
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
306
+ }
307
+
308
+ t.type_of_resource(:path=>"typeOfResource") {
309
+ t.manuscript(:path=>{:attribute=>"manuscript"})
310
+ }
311
+
312
+
313
+ t.genre_basic(:path=>"genre", :attributes=>{:displayLabel => "general"})
314
+
315
+ t.genre_specific(:path=>"genre", :attributes=>{:displayLabel => "specific"})
316
+
317
+ t.origin_info(:path=>"originInfo") {
318
+ t.publisher(:path=>"publisher")
319
+ t.place(:path=>"place") {
320
+ t.place_term(:path=>"placeTerm", :attributes=>{:type=>'text'})
321
+ }
322
+ t.issuance(:path=>"issuance")
323
+ t.edition(:path=>"edition")
324
+ t.event_type(:path=>{:attribute=>"eventType"})
325
+ }
326
+
327
+ t.item_location(:path=>"location") {
328
+ t.physical_location(:path=>"physicalLocation") {
329
+ t.type(:path=>{:attribute=>"type"})
330
+ }
331
+ t.holding_simple(:path=>"holdingSimple") {
332
+ t.copy_information(:path=>"copyInformation") {
333
+ t.sub_location(:path=>"subLocation")
334
+ t.shelf_locator(:path=>"shelfLocator")
335
+ }
336
+ }
337
+ t.url(:path=>"url") {
338
+ t.usage(:path=>{:attribute=>"usage"})
339
+ t.access(:path=>{:attribute=>"access"})
340
+ }
341
+ }
342
+
343
+
344
+
345
+
346
+ t.identifier_accession :path => 'identifier', :attributes => { :type => "accession number" }
347
+ t.identifier_barcode :path => 'identifier', :attributes => { :type => "barcode" }
348
+ t.identifier_bpldc :path => 'identifier', :attributes => { :type => "bpldc number" }
349
+ t.identifier_other :path => 'identifier', :attributes => { :type => "other" }
350
+ t.isbn :path => 'identifier', :attributes => { :type => "isbn" }
351
+ t.local_other :path => 'identifier', :attributes => { :type => "local-other" }
352
+ t.lccn :path => 'identifier', :attributes => { :type => "lccn" }
353
+ t.local_accession :path => 'identifier', :attributes => { :type => "local-accession" }
354
+ t.local_call :path => 'identifier', :attributes => { :type => "local-call" }
355
+ t.local_barcode :path => 'identifier', :attributes => { :type => "local-barcode" }
356
+ t.identifier_uri :path => 'identifier', :attributes => { :type => "uri" }
357
+
358
+ t.physical_description(:path=>"physicalDescription") {
359
+ t.internet_media_type(:path=>"internetMediaType")
360
+ t.digital_origin(:path=>"digitalOrigin")
361
+ t.extent(:path=>"extent")
362
+ t.note(:path=>'note')
363
+ }
364
+
365
+ t.note(:path=>"note") {
366
+ t.type_at(:path=>{:attribute=>"type"})
367
+ }
368
+
369
+
370
+ t.personal_name(:path=>'mods/oxns:subject/oxns:name', :attributes=>{:type => "personal"}) {
371
+ t.name_part(:path=>"namePart[not(@type)]")
372
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
373
+ }
374
+
375
+ t.corporate_name(:path=>'mods/oxns:subject/oxns:name', :attributes=>{:type => "corporate"}) {
376
+ t.name_part(:path=>"namePart[not(@type)]")
377
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
378
+ }
379
+
380
+
381
+ t.subject do
382
+ t.topic
383
+ t.geographic(:path=>'geographic') {
384
+ t.display_label(:path=>{:attribute=>"displayLabel"})
385
+ }
386
+ t.authority(:path=>{:attribute=>"authority"})
387
+ t.valueURI(:path=>{:attribute=>"valueURI"})
388
+ t.authorityURI(:path=>{:attribute=>"authorityURI"})
389
+ t.personal_name(:path=>'name', :attributes=>{:type => "personal"}) {
390
+ t.name_part(:path=>"namePart[not(@type)]")
391
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
392
+ }
393
+ t.corporate_name(:path=>'name', :attributes=>{:type => "corporate"}) {
394
+ t.name_part(:path=>"namePart[not(@type)]")
395
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
396
+ }
397
+ t.conference_name(:path=>'name', :attributes=>{:type => "conference"}) {
398
+ t.name_part(:path=>"namePart[not(@type)]")
399
+ }
400
+ t.name(:path=>'name') {
401
+ t.name_part(:path=>"namePart[not(@type)]")
402
+ t.date(:path=>"namePart", :attributes=>{:type=>"date"})
403
+ t.name_part_actual(:path=>"namePart") {
404
+ t.type(:path=>{:attribute=>"type"})
405
+ }
406
+ t.type(:path=>{:attribute=>"type"})
407
+ t.authority(:path=>{:attribute=>"authority"})
408
+ t.authority_uri(:path=>{:attribute=>"authorityURI"})
409
+ t.value_uri(:path=>{:attribute=>"valueURI"})
410
+ }
411
+ t.hierarchical_geographic(:path=>"hierarchicalGeographic") {
412
+ t.continent
413
+ t.country
414
+ t.region
415
+ t.province
416
+ t.state
417
+ t.territory
418
+ t.county
419
+ t.island
420
+ t.city
421
+ t.city_section(:path=>"citySection")
422
+ t.area
423
+ t.extarea(:path=>"extraterrestrialArea")
424
+ }
425
+ t.cartographics {
426
+ t.coordinates
427
+ t.scale
428
+ t.projection
429
+ }
430
+ t.temporal(:path=>'temporal', :attributes=>{:encoding => "w3cdtf"}) {
431
+ t.point(:path=>{:attribute=>"point"})
432
+ }
433
+ t.title_info(:ref=>[:title_info]) {
434
+ t.title
435
+ }
436
+ t.genre {
437
+ t.authority(:path=>{:attribute=>"authority"})
438
+ t.authority_uri(:path=>{:attribute=>"authorityURI"})
439
+ t.value_uri(:path=>{:attribute=>"valueURI"})
440
+ }
441
+
442
+ end
443
+
444
+
445
+ t.related_item(:path=>"relatedItem") {
446
+ t.type(:path=>{:attribute=>"type"})
447
+ t.href(:path=>{:attribute=>'xlink:href'})
448
+ t.title_info(:path=>"titleInfo") {
449
+ t.title
450
+ t.nonSort(:path=>"nonSort")
451
+ }
452
+ t.identifier
453
+ t.location(:path=>'location') {
454
+ t.url(:path=>'url')
455
+ }
456
+ t.related_item(:ref=>[:related_series_item]) {
457
+ t.related_item(:ref=>[:related_series_item]) {
458
+ t.related_item(:ref=>[:related_series_item]) {
459
+ t.related_item(:ref=>[:related_series_item])
460
+ }
461
+ }
462
+ }
463
+ t.subseries(:path=>'relatedItem', :attributes=>{:type => "series"}) {
464
+ t.title_info(:path=>"titleInfo") {
465
+ t.title
466
+ t.nonSort(:path=>"nonSort")
467
+ }
468
+ t.subsubseries(:path=>'relatedItem', :attributes=>{:type => "series"}) {
469
+ t.title_info(:path=>"titleInfo") {
470
+ t.title
471
+ t.nonSort(:path=>"nonSort")
472
+ }
473
+ }
474
+ }
475
+
476
+ }
477
+
478
+ t.related_series_item(:path=>'relatedItem') {
479
+ t.type(:path=>{:attribute=>"type"})
480
+ t.title_info(:path=>"titleInfo") {
481
+ t.title
482
+ t.nonSort(:path=>"nonSort")
483
+ }
484
+ }
485
+
486
+
487
+ #t.subseries(:path=>'mods/oxns:relatedItem/oxns:relatedItem', :attributes=>{:type => "series"}) {
488
+ # t.title_info(:path=>"titleInfo") {
489
+ # t.title
490
+ # t.nonSort(:path=>"nonSort")
491
+ # }
492
+ #}
493
+
494
+ t.use_and_reproduction(:path=>"accessCondition", :attributes=>{:type=>"use and reproduction"}) {
495
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
496
+ t.type(:path=>{:attribute=>"type"})
497
+ }
498
+
499
+ t.restriction_on_access(:path=>"accessCondition", :attributes=>{:type=>"restrictions on access"}) {
500
+ t.displayLabel :path=>{:attribute=>'displayLabel'}
501
+ t.type(:path=>{:attribute=>"type"})
502
+ }
503
+
504
+
505
+
506
+ t.date(:path=>"originInfo") {
507
+ t.date_other(:path=>"dateOther") {
508
+ t.encoding(:path=>{:attribute=>"encoding"})
509
+ t.key_date(:path=>{:attribute=>"keyDate"})
510
+ t.type(:path=>{:attribute=>"type"})
511
+ t.qualifier(:path=>{:attribute=>"qualifier"})
512
+ }
513
+ t.dates_created(:path=>"dateCreated") {
514
+ t.encoding(:path=>{:attribute=>"encoding"})
515
+ t.key_date(:path=>{:attribute=>"keyDate"})
516
+ t.point(:path=>{:attribute=>"point"})
517
+ t.qualifier(:path=>{:attribute=>"qualifier"})
518
+ }
519
+ t.dates_issued(:path=>"dateIssued") {
520
+ t.encoding(:path=>{:attribute=>"encoding"})
521
+ t.key_date(:path=>{:attribute=>"keyDate"})
522
+ t.point(:path=>{:attribute=>"point"})
523
+ t.qualifier(:path=>{:attribute=>"qualifier"})
524
+ }
525
+ t.dates_copyright(:path=>"copyrightDate") {
526
+ t.encoding(:path=>{:attribute=>"encoding"})
527
+ t.key_date(:path=>{:attribute=>"keyDate"})
528
+ t.point(:path=>{:attribute=>"point"})
529
+ t.qualifier(:path=>{:attribute=>"qualifier"})
530
+ }
531
+
532
+ }
533
+
534
+ t.role {
535
+ t.text(:path=>'roleTerm',:attributes=>{:type=>'text', :authority=>'marcrelator', :authorityURI=>'http://id.loc.gov/vocabulary/relators'}) {
536
+ t.valueURI(:path=>{:attribute=>'valueURI'})
537
+ }
538
+ t.code(:path=>'roleTerm',:attributes=>{:type=>'code'})
539
+ }
540
+
541
+ t.language(:path=>"language") {
542
+ t.language_term(:path=>"languageTerm") {
543
+ t.lang_val_uri(:path=>{:attribute=>"valueURI"})
544
+ }
545
+ }
546
+
547
+ t.record_info(:path=>'recordInfo') {
548
+ t.description_standard(:path=>'descriptionStandard', :attributes=>{:authority=>"marcdescription"})
549
+ t.record_content_source(:path=>'recordContentSource') {
550
+ t.authority(:path=>{:attribute=>"authority"})
551
+ }
552
+ t.record_origin(:path=>'recordOrigin')
553
+ t.language_of_cataloging(:path=>'languageOfCataloging') {
554
+ t.language_term(:path=>'languageTerm', :attributes => { :authority => 'iso639-2b',:authorityURI=> 'http://id.loc.gov/vocabulary/iso639-2', :type=>'text', :valueURI=>'http://id.loc.gov/vocabulary/iso639-2/eng' })
555
+ }
556
+ }
557
+
558
+
559
+ t.table_of_contents(:path=>'tableOfContents')
560
+
561
+
562
+ end
563
+
564
+ # Blocks to pass into Nokogiri::XML::Builder.new()
565
+ =begin
566
+ define_template :name do |xml|
567
+ xml.name {
568
+ xml.namePart
569
+ xml.role {
570
+ xml.roleTerm(:authority => "marcrelator", :type => "text")
571
+ }
572
+ }
573
+ end
574
+
575
+ define_template :relatedItem do |xml|
576
+ xml.relatedItem {
577
+ xml.titleInfo {
578
+ xml.title
579
+ }
580
+ xml.location {
581
+ xml.url
582
+ }
583
+ }
584
+ end
585
+
586
+ define_template :related_citation do |xml|
587
+ xml.note(:type => "citation/reference")
588
+ end
589
+ =end
590
+
591
+ def self.xml_template
592
+ builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
593
+ xml.mods(MODS_PARAMS) {
594
+ xml.parent.namespace = xml.parent.namespace_definitions.find{|ns|ns.prefix=="mods"}
595
+
596
+ }
597
+ end
598
+ return builder.doc
599
+ end
600
+
601
+ def to_xml(xml = nil)
602
+ xml = self.ng_xml if xml.nil?
603
+ ng_xml = self.ng_xml
604
+ if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
605
+ ng_xml = self.class.generate(self.class.root_property_ref, "")
606
+ if xml.root.nil?
607
+ xml = ng_xml
608
+ end
609
+ end
610
+
611
+ unless xml == ng_xml || ng_xml.root.nil?
612
+ if xml.kind_of?(Nokogiri::XML::Document)
613
+ xml.root.add_child(ng_xml.root)
614
+ elsif xml.kind_of?(Nokogiri::XML::Node)
615
+ xml.add_child(ng_xml.root)
616
+ else
617
+ raise "You can only pass instances of Nokogiri::XML::Node into this method. You passed in #{xml}"
618
+ end
619
+ end
620
+
621
+ return xml.to_xml(:encoding=>'UTF-8').strip
622
+ end
623
+
624
+ #Required for Active Fedora 9
625
+ def prefix(path=nil)
626
+ return ''
627
+ end
628
+
629
+ =begin
630
+ def identifier=(values)
631
+ ng_xml.search(identifier.xpath, {oxns:"http://www.loc.gov/mods/v3"}).each do |n|
632
+ n.remove
633
+ end
634
+
635
+ super(values)
636
+
637
+ end
638
+ =end
639
+
640
+ #def insert_physical_description(media_type=nil, digital_origin=nil, media_type2=nil, note=nil)
641
+
642
+ def insert_digital_origin(digital_origin=nil)
643
+ physical_description_index = 0
644
+ origin_index = self.mods(0).physical_description(physical_description_index).digital_origin.count
645
+ self.mods(0).physical_description(physical_description_index).digital_origin(origin_index, digital_origin) unless digital_origin.blank?
646
+ end
647
+
648
+ def insert_physical_note(note=nil)
649
+ physical_description_index = 0
650
+ note_index = self.mods(0).physical_description(physical_description_index).note.count
651
+ self.mods(0).physical_description(physical_description_index).note(note_index, note) unless note.blank?
652
+ end
653
+
654
+ def remove_physical_description(index)
655
+ self.find_by_terms(:physical_description).slice(index.to_i).remove
656
+ end
657
+
658
+ def insert_media_type(media_type=nil)
659
+ physical_description_index = 0
660
+ media_type_index = self.mods(0).physical_description(physical_description_index).internet_media_type.count
661
+ self.mods(0).physical_description(physical_description_index).internet_media_type(media_type_index, media_type) unless media_type.blank? || self.mods(0).physical_description(physical_description_index).internet_media_type.include?(media_type)
662
+ end
663
+
664
+
665
+
666
+ define_template :language do |xml, value, code|
667
+ xml.language {
668
+ xml.languageTerm(:type=>"text", :authority=>"iso639-2b", :authorityURI=>"http://id.loc.gov/vocabulary/iso639-2", :valueURI=>code) {
669
+ xml.text value
670
+ }
671
+ }
672
+ end
673
+
674
+ def insert_language(value=nil, code='eng')
675
+ code = "http://id.loc.gov/vocabulary/iso639-2/#{code}" unless code.include?('http')
676
+ add_child_node(ng_xml.root, :language, value, code)
677
+ end
678
+
679
+ def remove_language(index)
680
+ self.find_by_terms(:language).slice(index.to_i).remove
681
+ end
682
+
683
+
684
+ def insert_rights(value=nil, type=nil, displayLabel=nil)
685
+ access_index = self.mods(0).accessCondition.count
686
+ self.mods(0).accessCondition(access_index, value) unless value.blank?
687
+ self.mods(0).accessCondition(access_index).type_at = type unless type.blank?
688
+ self.mods(0).accessCondition(access_index).displayLabel = displayLabel unless displayLabel.blank?
689
+ end
690
+
691
+
692
+ def insert_type_of_resource(value=nil, manuscript=nil)
693
+ resource_index = self.mods(0).type_of_resource.count
694
+ if !self.mods(0).type_of_resource.include?(value)
695
+ self.mods(0).type_of_resource(resource_index, value) unless value.blank?
696
+ self.mods(0).type_of_resource(resource_index).manuscript = 'yes' unless manuscript.blank?
697
+ end
698
+ end
699
+
700
+ def remove_type_of_resource(index)
701
+ self.find_by_terms(:type_of_resource).slice(index.to_i).remove
702
+ end
703
+
704
+ def insert_publisher(publisher=nil, place=nil)
705
+ origin_index = 0
706
+ publisher_index = self.mods(0).origin_info(origin_index).publisher.count
707
+ place_index = self.mods(0).origin_info(origin_index).place.count
708
+
709
+ self.mods(0).origin_info(origin_index).publisher(publisher_index, publisher) unless publisher.blank?
710
+ self.mods(0).origin_info(origin_index).place(place_index).place_term = place unless place.blank?
711
+ end
712
+
713
+ def remove_publisher(index)
714
+ self.find_by_terms(:mods, :publisher).slice(index.to_i).remove
715
+ end
716
+
717
+ def insert_issuance(issuance=nil)
718
+ origin_index = 0
719
+ issuance_index = self.mods(0).origin_info(origin_index).issuance.count
720
+
721
+ self.mods(0).origin_info(origin_index).issuance(issuance_index, issuance) unless issuance.blank?
722
+ end
723
+
724
+ def insert_edition(edition=nil)
725
+ origin_index = 0
726
+ edition_index = self.mods(0).origin_info(origin_index).edition.count
727
+
728
+ self.mods(0).origin_info(origin_index).edition(edition_index, edition) unless edition.blank?
729
+ end
730
+
731
+
732
+ def insert_genre(value=nil, value_uri=nil, authority=nil, display_label='specific')
733
+ #Prevent duplicates
734
+ if value.present? && !self.mods(0).genre.any?{ |genre| genre == value}
735
+ genre_index = self.mods(0).genre.count
736
+
737
+ self.mods(0).genre(genre_index, value) unless value.blank?
738
+
739
+ self.mods(0).genre(genre_index).authority = authority unless authority.blank?
740
+
741
+ if authority == 'gmgpc' || authority == 'lctgm'
742
+ self.mods(0).genre(genre_index).authorityURI = 'http://id.loc.gov/vocabulary/graphicMaterials'
743
+ elsif authority == 'lcsh'
744
+ self.mods(0).genre(genre_index).authorityURI = 'http://id.loc.gov/authorities/subjects'
745
+ elsif authority == 'aat'
746
+ self.mods(0).genre(genre_index).authorityURI = 'http://vocab.getty.edu/aat'
747
+ end
748
+
749
+ if value_uri.present? && value_uri.match(/^http/).blank?
750
+ if authority == 'marcgt'
751
+ value_uri = value_url
752
+ elsif authority == 'aat'
753
+ value_uri = 'http://vocab.getty.edu/aat/' + value_uri
754
+ elsif authority == 'gmgpc' || authority == 'lctgm'
755
+ value_uri = 'http://id.loc.gov/vocabulary/graphicMaterials/' + value_uri
756
+ end
757
+ end
758
+
759
+ self.mods(0).genre(genre_index).valueURI = value_uri unless value_uri.blank?
760
+
761
+ self.mods(0).genre(genre_index).displayLabel = display_label unless display_label.blank?
762
+ end
763
+
764
+
765
+ end
766
+
767
+ def remove_genre(index)
768
+ self.find_by_terms(:genre).slice(index.to_i).remove
769
+ end
770
+
771
+ define_template :access_links do |xml, preview, primary|
772
+ xml.location {
773
+ if preview != nil && preview.length > 0
774
+ xml.url(:access=>"preview") {
775
+ xml.text preview
776
+ }
777
+ end
778
+ xml.url(:usage=>"primary", :access=>"object in context") {
779
+ xml.text primary
780
+ }
781
+ }
782
+ end
783
+
784
+ def insert_access_links(preview=nil, primary=nil)
785
+ add_child_node(ng_xml.root, :access_links, preview, primary)
786
+ end
787
+
788
+ def remove_access_links(index)
789
+ self.find_by_terms(:access_links).slice(index.to_i).remove
790
+ end
791
+
792
+ def insert_geonames(geonames_id)
793
+ puts 'Geonames ID is: ' + geonames_id
794
+
795
+ #Duplicate Geonames value?
796
+ if self.subject.valueURI.include?(geonames_id)
797
+ return false
798
+ end
799
+
800
+ api_result = Geomash::Geonames.get_geonames_data(geonames_id)
801
+
802
+ puts 'API Result is: ' + api_result.to_s
803
+
804
+
805
+ subject_index = self.mods(0).subject.count
806
+
807
+ self.mods(0).subject(subject_index).authority = "geonames"
808
+ self.mods(0).subject(subject_index).valueURI = "http://sws.geonames.org/#{geonames_id}"
809
+ self.mods(0).subject(subject_index).authorityURI = 'http://sws.geonames.org'
810
+
811
+
812
+ self.mods(0).subject(subject_index).geographic = api_result[:hier_geo].values[-1]
813
+
814
+
815
+ #Insert Coordinates
816
+ if api_result[:coords] != nil
817
+ self.mods(0).subject(subject_index).cartographics.coordinates = api_result[:coords][:latitude] + "," + api_result[:coords][:longitude]
818
+ end
819
+ end
820
+
821
+ def insert_origin_event(event_type)
822
+ #Currently only supporting one elements...
823
+ origin_index = 0
824
+ self.mods(0).origin_info(origin_index).event_type = event_type unless event_type.blank?
825
+ end
826
+
827
+ def insert_tgn(tgn_id)
828
+ puts 'TGN ID is: ' + tgn_id
829
+
830
+ #Duplicate TGN value?
831
+ if self.subject.valueURI.include?(tgn_id)
832
+ return false
833
+ end
834
+
835
+ api_result = Geomash::TGN.get_tgn_data(tgn_id)
836
+
837
+ puts 'API Result is: ' + api_result.to_s
838
+
839
+ #FIXME: Only works for hier_geo places....
840
+ #Get rid of less specific matches... city level information should trump state level information.
841
+ if api_result[:hier_geo].present?
842
+ if api_result[:hier_geo][:city].present? && self.subject.hierarchical_geographic.present?
843
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
844
+ if self.mods(0).subject(subject_index).authority == ['tgn']
845
+ if self.mods(0).subject(subject_index).hierarchical_geographic(0).city.blank? && self.mods(0).subject(subject_index).hierarchical_geographic(0).state == [api_result[:hier_geo][:state]]
846
+ #Check to not remove non-hier geo cases... as actually more specific than just a state
847
+ if self.mods(0).subject(subject_index).geographic(0).blank?
848
+ self.mods(0).subject(subject_index, nil)
849
+ end
850
+ end
851
+ end
852
+ end
853
+
854
+ #Exit if same city match
855
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
856
+ if self.mods(0).subject(subject_index).authority == ['tgn']
857
+ if self.mods(0).subject(subject_index).hierarchical_geographic(0).city == [api_result[:hier_geo][:city]]
858
+ #Case of more specific in non_hier_geo...
859
+ if self.mods(0).subject(subject_index).geographic(0).blank? && api_result[:non_hier_geo].present?
860
+ self.mods(0).subject(subject_index, nil)
861
+ else
862
+ return false
863
+ end
864
+ end
865
+ end
866
+ end
867
+ #Exit check if trying to insert same state twice with no city
868
+ elsif api_result[:hier_geo][:city].blank? && api_result[:hier_geo][:state].present? && self.subject.hierarchical_geographic.present?
869
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
870
+ if self.mods(0).subject(subject_index).authority == ['tgn']
871
+ if self.mods(0).subject(subject_index).hierarchical_geographic(0).state == [api_result[:hier_geo][:state]]
872
+ #Case of more specific in non_hier_geo...
873
+ if self.mods(0).subject(subject_index).geographic(0).blank? && api_result[:non_hier_geo].present?
874
+ self.mods(0).subject(subject_index, nil)
875
+ else
876
+ return false
877
+ end
878
+ end
879
+ end
880
+ end
881
+ #Exit check if trying to insert the same area...
882
+ elsif api_result[:hier_geo][:city].blank? && api_result[:hier_geo][:area].present? && self.subject.hierarchical_geographic.present?
883
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
884
+ if self.mods(0).subject(subject_index).authority == ['tgn']
885
+ if self.mods(0).subject(subject_index).hierarchical_geographic(0).area == [api_result[:hier_geo][:area]]
886
+ #Case of more specific in non_hier_geo...
887
+ if self.mods(0).subject(subject_index).geographic(0).blank? && api_result[:non_hier_geo].present?
888
+ self.mods(0).subject(subject_index, nil)
889
+ else
890
+ return false
891
+ end
892
+ end
893
+ end
894
+ end
895
+ #Finally exit if inserting the same country...
896
+ elsif api_result[:hier_geo][:city].blank? && api_result[:hier_geo][:state].blank? && api_result[:hier_geo][:area].blank? && api_result[:hier_geo][:country].present? && self.subject.hierarchical_geographic.present?
897
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
898
+ if self.mods(0).subject(subject_index).authority == ['tgn']
899
+ if self.mods(0).subject(subject_index).hierarchical_geographic(0).country == [api_result[:hier_geo][:country]]
900
+ #Case of more specific in non_hier_geo...
901
+ if self.mods(0).subject(subject_index).geographic(0).blank? && api_result[:non_hier_geo].present?
902
+ self.mods(0).subject(subject_index, nil)
903
+ else
904
+ return false
905
+ end
906
+ end
907
+ end
908
+ end
909
+ end
910
+ end
911
+
912
+ if api_result[:non_hier_geo].present?
913
+ #Exit if same place match currently....
914
+ self.mods(0).subject.each_with_index do |ignored, subject_index|
915
+ if self.mods(0).subject(subject_index).authority == ['tgn']
916
+ if self.mods(0).subject(subject_index).geographic == [api_result[:non_hier_geo][:value]]
917
+ return false
918
+ end
919
+ end
920
+ end
921
+ end
922
+
923
+ subject_index = self.mods(0).subject.count
924
+
925
+ self.mods(0).subject(subject_index).authority = "tgn"
926
+ self.mods(0).subject(subject_index).valueURI = "http://vocab.getty.edu/tgn/#{tgn_id}"
927
+ self.mods(0).subject(subject_index).authorityURI = 'http://vocab.getty.edu/tgn/'
928
+
929
+ #Insert geographic text
930
+ if api_result[:non_hier_geo].present?
931
+ self.mods(0).subject(subject_index).geographic = api_result[:non_hier_geo][:value]
932
+ self.mods(0).subject(subject_index).geographic.display_label = api_result[:non_hier_geo][:qualifier] unless api_result[:non_hier_geo][:qualifier].blank?
933
+ end
934
+
935
+ #Insert hierarchicalGeographic text
936
+ if api_result[:hier_geo] != nil
937
+ api_result[:hier_geo].keys.reverse.each do |key|
938
+ key_with_equal = key.to_s + "="
939
+ self.mods(0).subject(subject_index).hierarchical_geographic.send(key_with_equal.to_sym, Bplmodels::DatastreamInputFuncs.utf8Encode(api_result[:hier_geo][key]))
940
+ end
941
+ end
942
+
943
+ #Insert Coordinates
944
+ if api_result[:coords] != nil
945
+ self.mods(0).subject(subject_index).cartographics.coordinates = api_result[:coords][:latitude] + "," + api_result[:coords][:longitude]
946
+ end
947
+ end
948
+
949
+ #usage=nil, supplied=nil, subtitle=nil, language=nil, type=nil, authority=nil, authorityURI=nil, valueURI=nil
950
+ def insert_title(nonSort=nil, main_title=nil, usage=nil, supplied=nil, type=nil, subtitle=nil, language=nil, display_label=nil, args={})
951
+ title_index = self.mods(0).title_info.count
952
+
953
+ self.mods(0).title_info(title_index).nonSort = nonSort unless nonSort.blank?
954
+ self.mods(0).title_info(title_index).main_title = main_title unless main_title.blank?
955
+
956
+ self.mods(0).title_info(title_index).usage = usage unless usage.blank?
957
+ self.mods(0).title_info(title_index).supplied = 'yes' unless supplied.blank? || supplied == 'no'
958
+
959
+ self.mods(0).title_info(title_index).type = type unless type.blank?
960
+
961
+ #Need to update previous titles to be translated now as well....
962
+ if type == 'translated' && usage == 'primary'
963
+ 0.upto title_index-1 do |pos|
964
+ if self.mods(0).title_info(pos).usage[0] == 'primary'
965
+ self.mods(0).title_info(pos).type = type
966
+ end
967
+ end
968
+ #Currently only main title has a blank type.... may want to pass this instead eventually if that changes.
969
+ elsif type.blank?
970
+ self.mods(0).title_info(title_index).display_label = 'primary_display'
971
+ end
972
+
973
+ self.mods(0).title_info(title_index).subtitle = subtitle unless subtitle.blank?
974
+
975
+ self.mods(0).title_info(title_index).language = language unless language.blank?
976
+
977
+ self.mods(0).title_info(title_index).display_label = display_label unless display_label.blank?
978
+
979
+ if args.present?
980
+ raise 'broken args in Active Fedora 7'
981
+ end
982
+
983
+ args.each do |key, value|
984
+ self.mods(0).title_info(title_index).send(key, Bplmodels::DatastreamInputFuncs.utf8Encode(value)) unless value.blank?
985
+ end
986
+ end
987
+
988
+ def remove_title(index)
989
+ self.find_by_terms(:mods, :title_info).slice(index.to_i).remove
990
+ end
991
+
992
+ #image.descMetadata.find_by_terms(:name).slice(0).set_attribute("new", "true")
993
+
994
+
995
+ def insert_name(name=nil, type=nil, authority=nil, value_uri=nil, role=nil, role_uri=nil, date=nil, args={})
996
+
997
+ name_index = self.mods(0).name.count
998
+ self.mods(0).name(name_index).type = type unless type.blank?
999
+ self.mods(0).name(name_index).authority = authority unless authority.blank?
1000
+ self.mods(0).name(name_index).valueURI = value_uri unless value_uri.blank?
1001
+
1002
+ if role.present?
1003
+ role_split = role.split('{|}') #new split var - see Arnold ticket
1004
+
1005
+ role_uri = '{|}{|}{|}{|}{|}' if role_uri.nil? #Very hackish...
1006
+ role_uri_split = role_uri.split('{|}') #new split var - see Arnold ticket
1007
+
1008
+ role_split.each_with_index do |single_role, role_index|
1009
+ self.mods(0).name(name_index).role(role_index).text = single_role unless single_role.blank?
1010
+ self.mods(0).name(name_index).role(role_index).text.valueURI = role_uri_split[role_index] unless role_uri_split[role_index].blank?
1011
+ end
1012
+
1013
+ end
1014
+
1015
+ if(authority == 'naf')
1016
+ self.mods(0).name(name_index).authorityURI = 'http://id.loc.gov/authorities/names'
1017
+ end
1018
+
1019
+ if type == 'corporate'
1020
+ name_array = Bplmodels::DatastreamInputFuncs.corpNamePartSplitter(name)
1021
+ name_array.each_with_index do |name_value, array_pos|
1022
+ self.mods(0).name(name_index).namePart(array_pos, name_value)
1023
+ end
1024
+ elsif type=='personal' && date.blank?
1025
+ name_hash = Bplmodels::DatastreamInputFuncs.persNamePartSplitter(name)
1026
+ self.mods(0).name(name_index).namePart = name_hash[:namePart]
1027
+ self.mods(0).name(name_index).date = name_hash[:datePart] unless name_hash[:datePart].blank?
1028
+ elsif date.present?
1029
+ self.mods(0).name(name_index).namePart = name
1030
+ self.mods(0).name(name_index).date = date
1031
+ else
1032
+ self.mods(0).name(name_index).namePart = name
1033
+ end
1034
+ args.each do |key, value|
1035
+ self.mods(0).name(name_index).send(key, Bplmodels::DatastreamInputFuncs.utf8Encode(value)) unless value.blank?
1036
+ end
1037
+ end
1038
+
1039
+
1040
+ def remove_name(index)
1041
+ self.find_by_terms(:mods, :name).slice(index.to_i).remove
1042
+ end
1043
+
1044
+ #test = ["test1", "test2"]
1045
+ #test.each do |k|
1046
+ #define_method "current_#{k.underscore}" do
1047
+ #puts k.underscore
1048
+ #end
1049
+ #end
1050
+
1051
+ def insert_oai_date(date)
1052
+ #converted = Bplmodels::DatastreamInputFuncs.convert_to_mods_date(date)
1053
+ converted = BplEnrich::Dates.standardize(date)
1054
+
1055
+ #date_index = self.date.length
1056
+ date_index = 0
1057
+ dup_found = false
1058
+
1059
+ #Prevent duplicate entries... Using a flag as keep the potential note?
1060
+ (self.mods(0).date(date_index).dates_created.length-1).times do |index|
1061
+ if converted.has_key?(:single_date)
1062
+ if self.mods(0).date(date_index).dates_created(index).point.blank? && self.mods(0).date(date_index).dates_created(index).first == converted[:single_date]
1063
+ dup_found = true
1064
+ end
1065
+ elsif converted.has_key?(:date_range)
1066
+ if self.mods(0).date(date_index).dates_created(index).point == 'start' && self.mods(0).date(date_index).dates_created(index).first == converted[:date_range][:start]
1067
+ if self.mods(0).date(date_index).dates_created(index+1).point == 'end' && self.mods(0).date(date_index).dates_created(index+1).first == converted[:date_range][:end]
1068
+ dup_found = true
1069
+ end
1070
+
1071
+ end
1072
+ end
1073
+ end
1074
+
1075
+ if !dup_found
1076
+ if converted.has_key?(:single_date) && !self.date.dates_created.include?(converted[:single_date])
1077
+ date_created_index = self.date(date_index).dates_created.length
1078
+ self.date(date_index).dates_created(date_created_index, converted[:single_date])
1079
+ self.date(date_index).dates_created(date_created_index).encoding = 'w3cdtf'
1080
+ if date_created_index == 0
1081
+ self.date(date_index).dates_created(date_created_index).key_date = 'yes'
1082
+ end
1083
+
1084
+ if converted.has_key?(:date_qualifier)
1085
+ self.date(date_index).dates_created(date_created_index).qualifier = converted[:date_qualifier]
1086
+ end
1087
+ elsif converted.has_key?(:date_range)
1088
+ date_created_index = self.date(date_index).dates_created.length
1089
+ self.date(date_index).dates_created(date_created_index, converted[:date_range][:start])
1090
+ self.date(date_index).dates_created(date_created_index).encoding = 'w3cdtf'
1091
+ if date_created_index == 0
1092
+ self.date(date_index).dates_created(date_created_index).key_date = 'yes'
1093
+ end
1094
+ self.date(date_index).dates_created(date_created_index).point = 'start'
1095
+ self.date(date_index).dates_created(date_created_index).qualifier = converted[:date_qualifier]
1096
+
1097
+ date_created_index = self.date(date_index).dates_created.length
1098
+ self.date(date_index).dates_created(date_created_index, converted[:date_range][:end])
1099
+ self.date(date_index).dates_created(date_created_index).encoding = 'w3cdtf'
1100
+ self.date(date_index).dates_created(date_created_index).point = 'end'
1101
+ self.date(date_index).dates_created(date_created_index).qualifier = converted[:date_qualifier]
1102
+ end
1103
+ end
1104
+
1105
+
1106
+
1107
+ self.insert_note(converted[:date_note],"date") unless !converted.has_key?(:date_note)
1108
+
1109
+ end
1110
+
1111
+ def insert_oai_date_issued(date)
1112
+ #converted = Bplmodels::DatastreamInputFuncs.convert_to_mods_date(date)
1113
+ converted = BplEnrich::Dates.standardize(date)
1114
+
1115
+
1116
+ #date_index = self.date.length
1117
+ date_index = 0
1118
+
1119
+ if converted.has_key?(:single_date)
1120
+ date_created_index = self.date(date_index).dates_issued.length
1121
+ self.date(date_index).dates_issued(date_created_index, converted[:single_date])
1122
+ self.date(date_index).dates_issued(date_created_index).encoding = 'w3cdtf'
1123
+ if date_created_index == 0
1124
+ self.date(date_index).dates_issued(date_created_index).key_date = 'yes'
1125
+ end
1126
+
1127
+ if converted.has_key?(:date_qualifier)
1128
+ self.date(date_index).dates_issued(date_created_index).qualifier = converted[:date_qualifier]
1129
+ end
1130
+ elsif converted.has_key?(:date_range)
1131
+ date_created_index = self.date(date_index).dates_issued.length
1132
+ self.date(date_index).dates_issued(date_created_index, converted[:date_range][:start])
1133
+ self.date(date_index).dates_issued(date_created_index).encoding = 'w3cdtf'
1134
+ if date_created_index == 0
1135
+ self.date(date_index).dates_issued(date_created_index).key_date = 'yes'
1136
+ end
1137
+ self.date(date_index).dates_issued(date_created_index).point = 'start'
1138
+ self.date(date_index).dates_issued(date_created_index).qualifier = converted[:date_qualifier]
1139
+
1140
+ date_created_index = self.date(date_index).dates_issued.length
1141
+ self.date(date_index).dates_issued(date_created_index, converted[:date_range][:end])
1142
+ self.date(date_index).dates_issued(date_created_index).encoding = 'w3cdtf'
1143
+ self.date(date_index).dates_issued(date_created_index).point = 'end'
1144
+ self.date(date_index).dates_issued(date_created_index).qualifier = converted[:date_qualifier]
1145
+ end
1146
+
1147
+ self.insert_note(converted[:date_note],"date") unless !converted.has_key?(:date_note)
1148
+
1149
+ end
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+ def insert_date(date_type, dateStarted=nil, dateEnding=nil, dateQualifier=nil, dateOther=nil, keydate=nil)
1156
+ #begin
1157
+
1158
+ #date_index = self.mods(0).date.count
1159
+ date_index = 0
1160
+
1161
+ #This is horrid. Can't use count as other elements use origin_info at the same depth....
1162
+ if keydate.blank?
1163
+ keydate = true if (self.mods(0).date.dates_created.key_date.blank? and self.mods(0).date.dates_issued.key_date.blank? and self.mods(0).date.dates_copyright.key_date.blank? and self.mods(0).date.date_other.key_date.blank?)
1164
+ keydate ||= false
1165
+ end
1166
+
1167
+ date_type = 'dates_created' if date_type == 'dateCreated'
1168
+ date_type = 'dates_copyright' if date_type == 'copyrightDate'
1169
+ date_type = 'dates_issued' if date_type == 'dateIssued'
1170
+ date_type = 'date_other' if date_type == 'dateOther'
1171
+
1172
+ date_type_with_equal = date_type + '='
1173
+
1174
+ #Range case - broken...fixme ... under same mods:originInfo ?
1175
+ if dateStarted.present? and dateEnding.present?
1176
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).point = 'start'
1177
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).encoding = 'w3cdtf'
1178
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).qualifier = dateQualifier unless dateQualifier.blank?
1179
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).key_date = "yes" unless keydate == false
1180
+
1181
+ self.mods(0).date(date_index).send(date_type.to_sym, 1).point = 'end'
1182
+ self.mods(0).date(date_index).send(date_type.to_sym, 1).encoding = 'w3cdtf'
1183
+ self.mods(0).date(date_index).send(date_type.to_sym, 1).qualifier = dateQualifier unless dateQualifier.blank?
1184
+
1185
+ #Hackish way to set the node values....
1186
+ self.mods(0).date(date_index).send(date_type_with_equal.to_sym, [dateStarted, dateEnding])
1187
+ elsif dateStarted.present?
1188
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).encoding = 'w3cdtf'
1189
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).qualifier = dateQualifier unless dateQualifier.blank?
1190
+ self.mods(0).date(date_index).send(date_type.to_sym, 0).key_date = "yes" unless keydate == false
1191
+ self.mods(0).date(date_index).send(date_type_with_equal.to_sym, dateStarted)
1192
+ elsif dateOther.present?
1193
+ self.mods(0).date(date_index).send(date_type_with_equal.to_sym, dateOther)
1194
+ end
1195
+
1196
+
1197
+ end
1198
+
1199
+
1200
+
1201
+ define_template :date_issued do |xml, dateStarted, dateEnding, dateQualifier|
1202
+
1203
+ if dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1204
+ xml.originInfo {
1205
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start", :qualifier=>dateQualifier) {
1206
+ xml.text dateStarted
1207
+ }
1208
+ xml.dateIssued(:encoding=>"w3cdtf", :point=>"end", :qualifier=>dateQualifier) {
1209
+ xml.text dateEnding
1210
+ }
1211
+ }
1212
+ elsif dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0
1213
+ xml.originInfo {
1214
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start") {
1215
+ xml.text dateStarted
1216
+ }
1217
+ xml.dateIssued(:encoding=>"w3cdtf", :point=>"end") {
1218
+ xml.text dateEnding
1219
+ }
1220
+ }
1221
+ elsif dateStarted != nil && dateStarted.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1222
+ xml.originInfo {
1223
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :qualifier=>dateQualifier) {
1224
+ xml.text dateStarted
1225
+ }
1226
+ }
1227
+ elsif dateStarted != nil && dateStarted.length > 0
1228
+ xml.originInfo {
1229
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes") {
1230
+ xml.text dateStarted
1231
+ }
1232
+ }
1233
+ else
1234
+ #puts "error in dates?"
1235
+
1236
+ end
1237
+ end
1238
+
1239
+ define_template :date_issued_partial do |xml, dateStarted, dateEnding, dateQualifier|
1240
+
1241
+ if dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1242
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start", :qualifier=>dateQualifier) {
1243
+ xml.text dateStarted
1244
+ }
1245
+ xml.dateIssued(:encoding=>"w3cdtf", :point=>"end", :qualifier=>dateQualifier) {
1246
+ xml.text dateEnding
1247
+ }
1248
+ elsif dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0
1249
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start") {
1250
+ xml.text dateStarted
1251
+ }
1252
+ xml.dateIssued(:encoding=>"w3cdtf", :point=>"end") {
1253
+ xml.text dateEnding
1254
+ }
1255
+ elsif dateStarted != nil && dateStarted.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1256
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes", :qualifier=>dateQualifier) {
1257
+ xml.text dateStarted
1258
+ }
1259
+ elsif dateStarted != nil && dateStarted.length > 0
1260
+ xml.dateIssued(:encoding=>"w3cdtf", :keyDate=>"yes") {
1261
+ xml.text dateStarted
1262
+ }
1263
+ else
1264
+ #puts "error in dates?"
1265
+
1266
+ end
1267
+ end
1268
+
1269
+ def insert_date_issued(dateStarted=nil, dateEnding=nil, dateQualifier=nil)
1270
+ #begin
1271
+ if self.find_by_terms(:origin_info) != nil && self.find_by_terms(:origin_info).slice(0) != nil
1272
+ add_child_node(self.find_by_terms(:origin_info).slice(0), :date_issued_partial, dateStarted, dateEnding, dateQualifier)
1273
+ else
1274
+ add_child_node(ng_xml.root, :date_issued, dateStarted, dateEnding, dateQualifier)
1275
+ end
1276
+
1277
+ #rescue OM::XML::Terminology::BadPointerError
1278
+ #add_child_node(ng_xml.root, :date, dateStarted, dateEnding, dateQualifier, dateOther)
1279
+ #end
1280
+
1281
+
1282
+ end
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+ define_template :date_copyright do |xml, dateStarted, dateEnding, dateQualifier|
1289
+
1290
+ if dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1291
+ xml.originInfo {
1292
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start", :qualifier=>dateQualifier) {
1293
+ xml.text dateStarted
1294
+ }
1295
+ xml.copyrightDate(:encoding=>"w3cdtf", :point=>"end", :qualifier=>dateQualifier) {
1296
+ xml.text dateEnding
1297
+ }
1298
+ }
1299
+ elsif dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0
1300
+ xml.originInfo {
1301
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start") {
1302
+ xml.text dateStarted
1303
+ }
1304
+ xml.copyrightDate(:encoding=>"w3cdtf", :point=>"end") {
1305
+ xml.text dateEnding
1306
+ }
1307
+ }
1308
+ elsif dateStarted != nil && dateStarted.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1309
+ xml.originInfo {
1310
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :qualifier=>dateQualifier) {
1311
+ xml.text dateStarted
1312
+ }
1313
+ }
1314
+ elsif dateStarted != nil && dateStarted.length > 0
1315
+ xml.originInfo {
1316
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes") {
1317
+ xml.text dateStarted
1318
+ }
1319
+ }
1320
+ else
1321
+ #puts "error in dates?"
1322
+
1323
+ end
1324
+ end
1325
+
1326
+ define_template :date_copyright_partial do |xml, dateStarted, dateEnding, dateQualifier|
1327
+
1328
+ if dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1329
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start", :qualifier=>dateQualifier) {
1330
+ xml.text dateStarted
1331
+ }
1332
+ xml.copyrightDate(:encoding=>"w3cdtf", :point=>"end", :qualifier=>dateQualifier) {
1333
+ xml.text dateEnding
1334
+ }
1335
+ elsif dateStarted != nil && dateStarted.length > 0 && dateEnding != nil && dateEnding.length > 0
1336
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :point=>"start") {
1337
+ xml.text dateStarted
1338
+ }
1339
+ xml.copyrightDate(:encoding=>"w3cdtf", :point=>"end") {
1340
+ xml.text dateEnding
1341
+ }
1342
+ elsif dateStarted != nil && dateStarted.length > 0 && dateQualifier!= nil && dateQualifier.length > 0
1343
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes", :qualifier=>dateQualifier) {
1344
+ xml.text dateStarted
1345
+ }
1346
+ elsif dateStarted != nil && dateStarted.length > 0
1347
+ xml.copyrightDate(:encoding=>"w3cdtf", :keyDate=>"yes") {
1348
+ xml.text dateStarted
1349
+ }
1350
+ else
1351
+ #puts "error in dates?"
1352
+
1353
+ end
1354
+ end
1355
+
1356
+ def insert_date_copyright(dateStarted=nil, dateEnding=nil, dateQualifier=nil)
1357
+ #begin
1358
+ if self.find_by_terms(:origin_info) != nil && self.find_by_terms(:origin_info).slice(0) != nil
1359
+ add_child_node(self.find_by_terms(:origin_info).slice(0), :date_copyright_partial, dateStarted, dateEnding, dateQualifier)
1360
+ else
1361
+ add_child_node(ng_xml.root, :date_copyright, dateStarted, dateEnding, dateQualifier)
1362
+ end
1363
+
1364
+
1365
+ end
1366
+
1367
+
1368
+
1369
+ =begin
1370
+ define_template :internet_media do |xml, value|
1371
+ xml.internetMediaType(value)
1372
+ end
1373
+
1374
+
1375
+ def insert_internet_media(value=nil)
1376
+ if(value != nil && value.length > 1 && value != "image/jpeg")
1377
+ add_child_node(self.find_by_terms(:physical_description).slice(0), :internet_media, value)
1378
+ end
1379
+ end
1380
+
1381
+ def remove_value(index)
1382
+ self.find_by_terms(:internet_media).slice(index.to_i).remove
1383
+ end
1384
+ =end
1385
+
1386
+
1387
+ define_template :extent do |xml, extent|
1388
+ xml.extent(extent)
1389
+ end
1390
+
1391
+ def insert_extent(extent=nil)
1392
+ self.mods(0).physical_description(0).extent(0, extent) unless extent.blank?
1393
+ end
1394
+
1395
+ def remove_extent(index)
1396
+ self.find_by_terms(:extent).slice(index.to_i).remove
1397
+ end
1398
+
1399
+ def insert_note(note=nil, noteQualifier=nil)
1400
+ note_index = self.mods(0).note.count
1401
+ self.mods(0).note(note_index, note) unless note.blank?
1402
+ self.mods(0).note(note_index).type_at = noteQualifier unless noteQualifier.blank?
1403
+ end
1404
+
1405
+ def remove_note(index)
1406
+ self.find_by_terms(:note).slice(index.to_i).remove
1407
+ end
1408
+
1409
+ #usage=nil, supplied=nil, subtitle=nil, language=nil, type=nil, authority=nil, authorityURI=nil, valueURI=nil
1410
+ def insert_subject_title(main_title=nil, authority=nil, valueURI=nil, type=nil)
1411
+ if main_title.present?
1412
+ subject_index = self.mods(0).subject.count
1413
+ sorted_title = Bplmodels::DatastreamInputFuncs.getProperTitle(main_title)
1414
+ title = sorted_title[1]
1415
+ nonSort = sorted_title[0]
1416
+
1417
+ self.mods(0).subject(subject_index).title_info(0).nonSort = nonSort unless nonSort.blank?
1418
+ self.mods(0).subject(subject_index).title_info(0).main_title = title unless title.blank?
1419
+ self.mods(0).subject(subject_index).title_info(0).type = type unless type.blank?
1420
+
1421
+ self.mods(0).subject(subject_index).title_info(0).authority = authority unless authority.blank?
1422
+ if authority == 'lctgm'
1423
+ self.mods(0).subject(subject_index).title_info(0).authorityURI = 'http://id.loc.gov/vocabulary/graphicMaterials'
1424
+ elsif authority == 'lcsh'
1425
+ self.mods(0).subject(subject_index).title_info(0).authorityURI = 'http://id.loc.gov/authorities/subjects'
1426
+ elsif authority == 'naf'
1427
+ self.mods(0).subject(subject_index).title_info(0).authorityURI = 'http://id.loc.gov/authorities/names'
1428
+ end
1429
+
1430
+ self.mods(0).subject(subject_index).title_info(0).valueURI = valueURI unless valueURI.blank?
1431
+ end
1432
+
1433
+ end
1434
+
1435
+
1436
+ def insert_subject_topic(topic=nil, valueURI=nil, authority=nil)
1437
+ if topic.present? && !self.mods(0).subject.topic.any?{ |top| top == topic }
1438
+ subject_index = self.mods(0).subject.count
1439
+ self.mods(0).subject(subject_index).topic = topic unless topic.blank?
1440
+ self.mods(0).subject(subject_index).valueURI = valueURI unless valueURI.blank?
1441
+ self.mods(0).subject(subject_index).authority = authority unless authority.blank?
1442
+ if authority == 'lctgm'
1443
+ self.mods(0).subject(subject_index).authorityURI = 'http://id.loc.gov/vocabulary/graphicMaterials'
1444
+ elsif authority == 'lcsh'
1445
+ self.mods(0).subject(subject_index).authorityURI = 'http://id.loc.gov/authorities/subjects'
1446
+ elsif authority == 'aat'
1447
+ self.mods(0).subject(subject_index).authorityURI = 'http://vocab.getty.edu/aat/'
1448
+ end
1449
+
1450
+ end
1451
+ end
1452
+
1453
+ def remove_subject_topic(index)
1454
+ self.find_by_terms(:mods, :subject_topic).slice(index.to_i).remove
1455
+ end
1456
+
1457
+ def insert_series(series)
1458
+ if series.present?
1459
+ top_level_insert_position = self.mods(0).related_item.length
1460
+
1461
+ 0.upto self.mods(0).related_item.length-1 do |pos|
1462
+ if self.mods(0).related_item(pos).type == ['series']
1463
+ top_level_insert_position = pos
1464
+ end
1465
+ end
1466
+
1467
+ if self.mods(0).related_item(top_level_insert_position).blank?
1468
+ self.mods(0).related_item(top_level_insert_position).type = 'series'
1469
+ self.mods(0).related_item(top_level_insert_position).title_info.title = series
1470
+ elsif self.mods(0).related_item(top_level_insert_position).related_item(0).blank?
1471
+ self.mods(0).related_item(top_level_insert_position).related_item(0).type = 'series'
1472
+ self.mods(0).related_item(top_level_insert_position).related_item(0).title_info.title = series
1473
+ elsif self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).blank?
1474
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).type = 'series'
1475
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).title_info.title = series
1476
+ elsif self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).blank?
1477
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).type = 'series'
1478
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).title_info.title = series
1479
+ elsif self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).related_item(0).blank?
1480
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).related_item(0).type = 'series'
1481
+ self.mods(0).related_item(top_level_insert_position).related_item(0).related_item(0).related_item(0).related_item(0).title_info.title = series
1482
+ end
1483
+
1484
+ end
1485
+
1486
+ end
1487
+
1488
+ def insert_subject_temporal(date)
1489
+ #converted = Bplmodels::DatastreamInputFuncs.convert_to_mods_date(date)
1490
+ duplicate = false
1491
+ converted = BplEnrich::Dates.standardize(date)
1492
+
1493
+ subject_index = self.mods(0).subject.count
1494
+
1495
+ if converted.has_key?(:single_date)
1496
+ #Check for duplicates
1497
+ (0..self.mods(0).subject.length-1).each do |index|
1498
+ if self.mods(0).subject(index).temporal == [converted[:single_date]]
1499
+ duplicate = true
1500
+ end
1501
+ end
1502
+ temporal_index = self.mods(0).subject(subject_index).temporal.length
1503
+ self.mods(0).subject(subject_index).temporal(temporal_index, converted[:single_date]) unless converted[:single_date].blank? || duplicate
1504
+ elsif converted.has_key?(:date_range)
1505
+ #Check for duplicates, FIXME: Is there case this doesn't work?
1506
+ (0..self.mods(0).subject.length-1).each do |index|
1507
+ if self.mods(0).subject(index).temporal == [converted[:date_range][:start], converted[:date_range][:end]]
1508
+ duplicate = true
1509
+ end
1510
+ end
1511
+
1512
+ temporal_index = self.mods(0).subject(subject_index).temporal.length
1513
+ self.mods(0).subject(subject_index).temporal(temporal_index, converted[:date_range][:start]) unless converted[:date_range][:start].blank? || duplicate
1514
+ self.mods(0).subject(subject_index).temporal(temporal_index).point = 'start' unless converted[:date_range][:start].blank? || duplicate
1515
+
1516
+ temporal_index = self.mods(0).subject(subject_index).temporal.length
1517
+ self.mods(0).subject(subject_index).temporal(temporal_index, converted[:date_range][:end]) unless converted[:date_range][:end].blank? || duplicate
1518
+ self.mods(0).subject(subject_index).temporal(temporal_index).point = 'end' unless converted[:date_range][:end].blank? || duplicate
1519
+ end
1520
+
1521
+ end
1522
+
1523
+ def insert_subject_date_fix_me(date_start, date_end)
1524
+ subject_index = self.mods(0).subject.count
1525
+
1526
+ temporal_index = self.mods(0).subject(subject_index).temporal.length
1527
+ self.mods(0).subject(subject_index).temporal(temporal_index, date_start) unless date_start.blank?
1528
+ self.mods(0).subject(subject_index).temporal(temporal_index).point = 'start' unless date_start.blank?
1529
+
1530
+ temporal_index = self.mods(0).subject(subject_index).temporal.length
1531
+ self.mods(0).subject(subject_index).temporal(temporal_index, date_end) unless date_end.blank?
1532
+ self.mods(0).subject(subject_index).temporal(temporal_index).point = 'end' unless date_end.blank?
1533
+ end
1534
+
1535
+ def insert_abstract(abstract=nil)
1536
+ abstract_index = self.mods(0).abstract.count
1537
+
1538
+ self.mods(0).abstract(abstract_index, abstract) unless abstract.blank?
1539
+ end
1540
+
1541
+ def insert_subject_name(name=nil, type=nil, authority=nil, valueURI=nil, date=nil)
1542
+ subject_index = self.mods(0).subject.count
1543
+
1544
+ if name.is_a?String
1545
+ self.mods(0).subject(subject_index).name(0).name_part_actual(0, name)
1546
+ #Date
1547
+ self.mods(0).subject(subject_index).name(0).name_part_actual(1, date) unless date.blank?
1548
+ self.mods(0).subject(subject_index).name(0).name_part_actual(1).type = 'date' unless date.blank?
1549
+
1550
+ elsif name.is_a?Array
1551
+ name.each_with_index do |name_part, index|
1552
+ self.mods(0).subject(subject_index).name(0).name_part_actual(index, Bplmodels::DatastreamInputFuncs.utf8Encode(name_part))
1553
+
1554
+ end
1555
+
1556
+ end
1557
+
1558
+ self.mods(0).subject(subject_index).name(0).authority = authority unless authority.blank?
1559
+ self.mods(0).subject(subject_index).name(0).authority_uri = 'http://id.loc.gov/authorities/names' if authority == 'naf'
1560
+ self.mods(0).subject(subject_index).name(0).value_uri = valueURI unless valueURI.blank?
1561
+ self.mods(0).subject(subject_index).name(0).type = type unless type.blank?
1562
+ end
1563
+
1564
+ define_template :subject_geographic do |xml, geographic, authority|
1565
+ if authority != nil and authority.length > 0
1566
+ xml.subject(:authority=>authority) {
1567
+ xml.geographic(geographic)
1568
+ }
1569
+ else
1570
+ xml.subject {
1571
+ xml.geographic(geographic)
1572
+ }
1573
+ end
1574
+
1575
+ end
1576
+
1577
+
1578
+ def insert_subject_geographic(geographic=nil, valueURI=nil, authority=nil, coordinates=nil)
1579
+ if geographic.present? && !self.mods(0).subject.geographic.any? {|geo| geo==geographic}
1580
+ subject_index = self.mods(0).subject.count
1581
+ self.mods(0).subject(subject_index).geographic = geographic unless geographic.blank?
1582
+ self.mods(0).subject(subject_index).valueURI = valueURI unless valueURI.blank?
1583
+ self.mods(0).subject(subject_index).authority = authority unless authority.blank?
1584
+ if authority == 'lctgm'
1585
+ self.mods(0).subject(subject_index).authorityURI = 'http://id.loc.gov/vocabulary/graphicMaterials'
1586
+ elsif authority == 'lcsh'
1587
+ self.mods(0).subject(subject_index).authorityURI = 'http://id.loc.gov/authorities/subjects'
1588
+ end
1589
+
1590
+ self.mods(0).subject(subject_index).cartographics(0).coordinates = coordinates unless coordinates.blank?
1591
+
1592
+ end
1593
+
1594
+ end
1595
+
1596
+ def remove_subject_geographic(index)
1597
+ self.find_by_terms(:subject_geographic).slice(index.to_i).remove
1598
+ end
1599
+
1600
+
1601
+ def insert_subject_cartographic(coordinates=nil, scale=nil, projection=nil)
1602
+ subject_index = self.mods(0).subject.count
1603
+ if coordinates.split(' ').length >= 3
1604
+ coordinates.scan(/([NSWE])([\d\.]+) *([NSWE])([\d\.]+) *([NSWE])([\d\.]+) *([NSWE])([\d\.]+)/).map do |dir1,deg1,dir2,deg2,dir3,deg3,dir4,deg4|
1605
+ deg1 = Float(deg1)
1606
+ deg2 = Float(deg2)
1607
+ deg3 = Float(deg3)
1608
+ deg4 = Float(deg4)
1609
+
1610
+ deg1 = deg1 * -1 if dir1 == 'S' || dir1 == 'W'
1611
+ deg2 = deg2 * -1 if dir2 == 'S' || dir2 == 'W'
1612
+ deg3 = deg3 * -1 if dir3 == 'S' || dir3 == 'W'
1613
+ deg4 = deg4 * -1 if dir4 == 'S' || dir4 == 'W'
1614
+
1615
+ if deg1 == deg2 && deg3 == deg4
1616
+ self.mods(0).subject(subject_index).cartographics(0).coordinates = deg3.to_s + ',' + deg1.to_s
1617
+ else
1618
+ self.mods(0).subject(subject_index).cartographics(0).coordinates = deg1.to_s + ' ' + deg4.to_s + ' ' + deg2.to_s + ' ' + deg3.to_s
1619
+ end
1620
+ end
1621
+ else
1622
+ #Remove spaces around the comma
1623
+ coordinates = coordinates.gsub(/ *, */, ',')
1624
+ self.mods(0).subject(subject_index).cartographics(0).coordinates = coordinates unless coordinates.blank?
1625
+ end
1626
+
1627
+ #FIXME: self.mods(0).subject(subject_index).cartographics(0).scale = scale unless scale.blank?
1628
+ #FIXME: self.mods(0).subject(subject_index).cartographics(0).projection = projection unless projection.blank?
1629
+
1630
+ end
1631
+
1632
+ def insert_subject_scale(scale=nil, projection=nil)
1633
+ subject_index = self.mods(0).subject.count
1634
+ self.mods(0).subject(subject_index).cartographics(0).scale = scale unless scale.blank?
1635
+ self.mods(0).subject(subject_index).cartographics(0).projection = projection unless projection.blank?
1636
+ end
1637
+
1638
+ def remove_subject_cartographic(index)
1639
+ self.find_by_terms(:subject_cartographic).slice(index.to_i).remove
1640
+ end
1641
+
1642
+ def insert_table_of_contents(value)
1643
+ contents_index = self.mods(0).table_of_contents.count
1644
+ self.mods(0).table_of_contents(contents_index, value) unless value.blank?
1645
+ end
1646
+
1647
+ def remove_table_of_contents(index)
1648
+ self.find_by_terms(:table_of_contents).slice(index.to_i).remove
1649
+ end
1650
+
1651
+ def insert_host(nonSort=nil, main_title=nil, identifier=nil, args={})
1652
+
1653
+ related_index = self.mods(0).related_item.count
1654
+
1655
+ self.mods(0).related_item(related_index).type = 'host' unless main_title.blank? && identifier.blank?
1656
+ self.mods(0).related_item(related_index).title_info(0).nonSort = nonSort unless nonSort.blank?
1657
+ self.mods(0).related_item(related_index).title_info(0).title = main_title unless main_title.blank?
1658
+ self.mods(0).related_item(related_index).identifier = identifier unless identifier.blank?
1659
+
1660
+ args.each do |key, value|
1661
+ self.mods(0).related_item(related_index).send(key, Bplmodels::DatastreamInputFuncs.utf8Encode(value)) unless value.blank?
1662
+ end
1663
+ end
1664
+
1665
+ def remove_host(index)
1666
+ self.find_by_terms(:mods, :host).slice(index.to_i).remove
1667
+ end
1668
+
1669
+
1670
+
1671
+
1672
+ define_template :related_item do |xml, value, qualifier|
1673
+ xml.relatedItem(:type=>qualifier) {
1674
+ xml.titleInfo {
1675
+ xml.title {
1676
+ xml.text value
1677
+ }
1678
+ }
1679
+
1680
+ }
1681
+ end
1682
+
1683
+ def insert_related_item(value=nil, qualifier=nil)
1684
+ if value != nil && value.length > 0
1685
+ add_child_node(ng_xml.root, :related_item, value, qualifier)
1686
+ end
1687
+ end
1688
+
1689
+ def remove_related_item(index)
1690
+ self.find_by_terms(:related_item).slice(index.to_i).remove
1691
+ end
1692
+
1693
+
1694
+ define_template :related_item_xref do |xml, value|
1695
+ xml.relatedItem(:type=>"isReferencedBy", 'xlink:href'=>value)
1696
+ end
1697
+
1698
+ def insert_related_item_xref(value=nil)
1699
+ puts 'told to insert related item xref'
1700
+ if value != nil && value.length > 0
1701
+ add_child_node(ng_xml.root, :related_item_xref, value)
1702
+ end
1703
+ end
1704
+
1705
+ def related_item_xref(index)
1706
+ self.find_by_terms(:related_item_xref).slice(index.to_i).remove
1707
+ end
1708
+
1709
+ def insert_related_item_url(value=nil)
1710
+ related_index = self.mods(0).related_item.count
1711
+
1712
+ self.mods(0).related_item(related_index).location(0).url = value unless value.blank?
1713
+ end
1714
+
1715
+ def remove_physical_location(index)
1716
+ self.find_by_terms(:physical_location).slice(index.to_i).remove
1717
+ end
1718
+
1719
+ def insert_physical_location(location=nil, sublocation=nil,shelf_locator=nil, location_type=nil)
1720
+ #Create a new tag unless there is a non-url tag already...
1721
+ location_index = self.mods(0).item_location.count
1722
+
1723
+ for index in 0..self.mods(0).item_location.count-1
1724
+ if self.mods(0).item_location(index).url.blank?
1725
+ location_index = index
1726
+ end
1727
+ end
1728
+
1729
+ physical_location_index = 0
1730
+
1731
+ self.mods(0).item_location(location_index).physical_location(physical_location_index, location) unless location.blank?
1732
+ self.mods(0).item_location(location_index).physical_location(physical_location_index).type = location_type unless location.blank?
1733
+ self.mods(0).item_location(location_index).holding_simple(0).copy_information(0).sub_location = sublocation unless sublocation.blank?
1734
+ self.mods(0).item_location(location_index).holding_simple(0).copy_information(0).shelf_locator = shelf_locator unless shelf_locator.blank?
1735
+ end
1736
+
1737
+ =begin
1738
+ def insert_location_url(url=nil, access=nil, usage=nil)
1739
+ location_index = self.mods(0).item_location.count
1740
+
1741
+ self.mods(0).item_location(location_index).url = url unless url.blank?
1742
+ self.mods(0).item_location(location_index).url(0).usage = usage unless usage.blank?
1743
+ self.mods(0).item_location(location_index).url(0).access = access unless access.blank?
1744
+
1745
+ end
1746
+ =end
1747
+
1748
+ def insert_location_url(url=nil, access=nil, usage=nil)
1749
+ location_index = self.mods(0).item_location.count
1750
+
1751
+ for index in 0..self.mods(0).item_location.count-1
1752
+ if self.mods(0).item_location(index).url.present?
1753
+ location_index = index
1754
+ end
1755
+ end
1756
+
1757
+ url_index = self.mods(0).item_location(location_index).url.count
1758
+
1759
+ self.mods(0).item_location(location_index).url(url_index, url) unless url.blank?
1760
+ self.mods(0).item_location(location_index).url(url_index).usage = usage unless usage.blank?
1761
+ self.mods(0).item_location(location_index).url(url_index).access = access unless access.blank?
1762
+
1763
+ end
1764
+
1765
+ def insert_identifier(identifier=nil, type=nil, display_label=nil, invalid=nil)
1766
+ identifier_index = self.mods(0).identifier.count
1767
+
1768
+ self.mods(0).identifier(identifier_index, identifier) unless identifier.blank?
1769
+ self.mods(0).identifier(identifier_index).type_at = type unless type.blank?
1770
+ self.mods(0).identifier(identifier_index).displayLabel = display_label unless display_label.blank?
1771
+ self.mods(0).identifier(identifier_index).invalid = 'yes' if (invalid.present? && invalid == 'yes')
1772
+ end
1773
+
1774
+ def remove_identifier(index)
1775
+ self.find_by_terms(:identifier).slice(index.to_i).remove
1776
+ end
1777
+
1778
+
1779
+ define_template :mcgreevy do |xml|
1780
+ xml.recordInfo {
1781
+ xml.recordContentSource {
1782
+ xml.text "Boston Public Library"
1783
+ }
1784
+ xml.recordOrigin {
1785
+ xml.text "human prepared"
1786
+ }
1787
+ xml.languageOfCataloging {
1788
+ xml.languageTerm(:authority=>"iso639-2b", :authorityURI=>"http://id.loc.gov/vocabulary/iso639-2", :type=>'text', :valueURI=>"http://id.loc.gov/vocabulary/iso639-2/eng") {
1789
+ xml.text "English"
1790
+ }
1791
+ }
1792
+
1793
+ }
1794
+ end
1795
+
1796
+ def insert_mcgreevy
1797
+ add_child_node(ng_xml.root, :mcgreevy)
1798
+ end
1799
+
1800
+ def remove_mcgreevy(index)
1801
+ self.find_by_terms(:mcgreevy).slice(index.to_i).remove
1802
+ end
1803
+
1804
+
1805
+ def insert_record_information(record_content_source, record_content_authority=nil)
1806
+ self.mods(0).record_info(0).record_content_source = record_content_source unless record_content_source.blank?
1807
+ self.mods(0).record_info(0).record_content_source(0).authority = record_content_authority unless record_content_authority.blank?
1808
+ self.mods(0).record_info(0).record_origin = 'human prepared'
1809
+ self.mods(0).record_info(0).language_of_cataloging(0).language_term = 'English'
1810
+ end
1811
+
1812
+
1813
+ def insert_new_node(term)
1814
+ add_child_node(ng_xml.root, term)
1815
+ end
1816
+
1817
+ def remove_node(term, index)
1818
+ node = self.find_by_terms(term.to_sym => index.to_i).first
1819
+ unless node.nil?
1820
+ node.remove
1821
+ self.dirty = true
1822
+ end
1823
+ end
1824
+
1825
+ end
1826
+ end