Class: Mods::Record
- Inherits:
-
Object
- Object
- Mods::Record
- Defined in:
- lib/mods/record.rb,
lib/mods/nom_terminology.rb
Constant Summary collapse
- NS_HASH =
{'m' => MODS_NS_V3}
- ATTRIBUTES =
['id', 'version']
Instance Attribute Summary collapse
-
#mods_ng_xml ⇒ Object
readonly
Returns the value of attribute mods_ng_xml.
-
#title_delimiter ⇒ Object
string to use when combining a title and subtitle, e.g.
Instance Method Summary collapse
-
#alternative_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo @type=“alternative”><title> elements.
-
#corporate_names ⇒ Object
use the displayForm of a corporate name if present otherwise, return all nameParts concatenated together.
-
#from_file(url) ⇒ Object
Convenience method to call Mods::Reader.new.from_file.
-
#from_nk_node(node) ⇒ Object
convenience method to call Mods::Reader.new.from_nk_node and to nom.
-
#from_str(str) ⇒ Object
convenience method to call Mods::Reader.new.from_str and to nom.
-
#from_url(url) ⇒ Object
Convenience method to call Mods::Reader.new.from_url and to nom.
-
#full_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> + (delim) + <subTitle> elements.
-
#initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) ⇒ Record
constructor
A new instance of Record.
-
#languages ⇒ Object
Translates iso-639 language codes, and leaves everything else alone.
- #method_missing(method_name, *args) ⇒ Object
-
#personal_names ⇒ Object
Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
-
#personal_names_w_dates ⇒ Object
Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
-
#set_terminology_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; WITH namespaces NOTES: 1.
-
#short_titles ⇒ Object
Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> elements but not including any titleInfo elements with type=“alternative”.
-
#sort_title ⇒ Object
String containing sortable title for this mods record.
-
#term_value(messages, sep = ' ') ⇒ String
get the value for the terms, as a String.
-
#term_values(messages) ⇒ Array<String>
get the values for the terms, as an Array.
- #with_attributes(element, attributes = [], method_mappings: { 'type' => 'type_at', 'ID' => 'id_at' }) ⇒ Object
Constructor Details
#initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) ⇒ Record
Returns a new instance of Record.
20 21 22 |
# File 'lib/mods/record.rb', line 20 def initialize(title_delimiter = Mods::TitleInfo::DEFAULT_TITLE_DELIM) @title_delimiter = title_delimiter end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/mods/record.rb', line 199 def method_missing method_name, *args if mods_ng_xml.respond_to?(method_name) mods_ng_xml.send(method_name, *args) else super.method_missing(method_name, *args) end end |
Instance Attribute Details
#mods_ng_xml ⇒ Object (readonly)
Returns the value of attribute mods_ng_xml.
7 8 9 |
# File 'lib/mods/record.rb', line 7 def mods_ng_xml @mods_ng_xml end |
#title_delimiter ⇒ Object
string to use when combining a title and subtitle, e.g.
for title "MODS" and subtitle "Metadata Odious Delimited Stuff" and delimiter " : "
we get "MODS : Metadata Odious Delimited Stuff"
11 12 13 |
# File 'lib/mods/record.rb', line 11 def title_delimiter @title_delimiter end |
Instance Method Details
#alternative_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo @type=“alternative”><title> elements.
136 137 138 |
# File 'lib/mods/record.rb', line 136 def alternative_titles @mods_ng_xml.title_info.alternative_title.map { |n| n } end |
#corporate_names ⇒ Object
use the displayForm of a corporate name if present
otherwise, return all nameParts concatenated together
160 161 162 |
# File 'lib/mods/record.rb', line 160 def corporate_names @mods_ng_xml.corporate_name.map { |n| n.display_value } end |
#from_file(url) ⇒ Object
Convenience method to call Mods::Reader.new.from_file. Returns a new instance of Mods::Record instantiated with the content from the given file.
55 56 57 58 59 |
# File 'lib/mods/record.rb', line 55 def from_file(url) @mods_ng_xml = Mods::Reader.new.from_file(url) set_terminology_ns(@mods_ng_xml) return self end |
#from_nk_node(node) ⇒ Object
convenience method to call Mods::Reader.new.from_nk_node and to nom
65 66 67 68 69 |
# File 'lib/mods/record.rb', line 65 def from_nk_node(node) @mods_ng_xml = Mods::Reader.new.from_nk_node(node) set_terminology_ns(@mods_ng_xml) return self end |
#from_str(str) ⇒ Object
convenience method to call Mods::Reader.new.from_str and to nom
28 29 30 31 32 33 |
# File 'lib/mods/record.rb', line 28 def from_str(str) @mods_ng_xml = Mods::Reader.new.from_str(str) set_terminology_ns(@mods_ng_xml) return self end |
#from_url(url) ⇒ Object
Convenience method to call Mods::Reader.new.from_url and to nom. Returns a new instance of Mods::Record instantiated with the content from the given URL.
42 43 44 45 46 |
# File 'lib/mods/record.rb', line 42 def from_url(url) @mods_ng_xml = Mods::Reader.new.from_url(url) set_terminology_ns(@mods_ng_xml) return self end |
#full_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> + (delim) + <subTitle> elements.
131 132 133 |
# File 'lib/mods/record.rb', line 131 def full_titles @mods_ng_xml.title_info.full_title.map { |n| n } end |
#languages ⇒ Object
Translates iso-639 language codes, and leaves everything else alone.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/mods/record.rb', line 166 def languages result = [] @mods_ng_xml.language.each { |n| # get languageTerm codes and add their translations to the result n.code_term.each { |ct| if ct..match(/^iso639/) begin vals = ct.text.split(/[,|\ ]/).reject {|x| x.strip.length == 0 } vals.each do |v| result << ISO_639.find(v.strip).english_name end rescue => e p "Couldn't find english name for #{ct.text}" result << ct.text end else result << ct.text end } # add languageTerm text values n.text_term.each { |tt| val = tt.text.strip result << val if val.length > 0 } # add language values that aren't in languageTerm subelement if n.languageTerm.size == 0 result << n.text end } result.uniq end |
#personal_names ⇒ Object
Returns Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
147 148 149 |
# File 'lib/mods/record.rb', line 147 def personal_names @mods_ng_xml.personal_name.map { |n| n.display_value } end |
#personal_names_w_dates ⇒ Object
Returns Array of Strings, each containing the computed display value of a personal name (see nom_terminology for algorithm).
153 154 155 |
# File 'lib/mods/record.rb', line 153 def personal_names_w_dates @mods_ng_xml.personal_name.map { |n| n.display_value_w_date } end |
#set_terminology_ns(mods_ng_xml) ⇒ Object
set the NOM terminology; WITH namespaces NOTES:
-
certain words, such as ‘type’ ‘name’ ‘description’ are reserved words in jruby or nokogiri
when the terminology would use these words, a suffix of '_at' is added if it is an attribute,
(e.g. 'type_at' for @type) and a suffix of '_el' is added if it is an element.
-
the underscore prefix variant terms are a way of making subterms for a node available
to any instance of said node and are not intended to be used externally
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/mods/nom_terminology.rb', line 34 def set_terminology_ns(mods_ng_xml) mods_ng_xml.set_terminology(:namespaces => { 'm' => Mods::MODS_NS }) do |t| # ABSTRACT ------------------------------------------------------------------------------- t.abstract :path => '/m:mods/m:abstract' t._abstract :path => '//m:abstract' do |n| with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel type]) end # ACCESS_CONDITION ----------------------------------------------------------------------- t.accessCondition :path => '/m:mods/m:accessCondition' t._accessCondition :path => '//m:accessCondition' do |n| with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel type]) end # CLASSIFICATION ------------------------------------------------------------------------- t.classification :path => '/m:mods/m:classification' t._classification :path => '//m:classification' do |n| with_attributes(n, Mods::AUTHORITY_ATTRIBS | Mods::LANG_ATTRIBS | %w[displayLabel edition]) end # EXTENSION ------------------------------------------------------------------------------ t.extension :path => '/m:mods/m:extension' t._extension :path => '//m:extension' do |n| with_attributes(n, %w[displayLabel]) end # GENRE ---------------------------------------------------------------------------------- t.genre :path => '/m:mods/m:genre' t._genre :path => '//m:genre' do |n| with_attributes(n, Mods::AUTHORITY_ATTRIBS | Mods::LANG_ATTRIBS | %w[displayLabel type usage]) end # IDENTIIER ------------------------------------------------------------------------------ t.identifier :path => '/m:mods/m:identifier' t._identifier :path => '//m:identifier' do |n| with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel type invalid]) end # LANGUAGE ------------------------------------------------------------------------------- t.language :path => '/m:mods/m:language' t._language :path => '//m:language' do |n| # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.languageTerm :path => 'm:languageTerm' n.code_term :path => 'm:languageTerm[@type="code"]' n.text_term :path => 'm:languageTerm[@type="text"]' n.scriptTerm :path => 'm:scriptTerm' end t._languageTerm :path => '//m:languageTerm' do |lt| with_attributes(lt, Mods::AUTHORITY_ATTRIBS | %w[type]) end # t.language # LOCATION ------------------------------------------------------------------------------- t.location :path => '/m:mods/m:location' t._location :path => '//m:location' do |n| # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.physicalLocation :path => 'm:physicalLocation' do |e| with_attributes(e, Mods::AUTHORITY_ATTRIBS | %w[displayLabel type]) end n.shelfLocator :path => 'm:shelfLocator' n.url :path => 'm:url' do |e| with_attributes(e, %w[dateLastAccessed displayLabel note access usage]) end n.holdingSimple :path => 'm:holdingSimple' do |h| h.copyInformation path: 'm:copyInformation' do |c| c.form path: 'm:form' do |f| with_attributes(f, Mods::LANG_ATTRIBS | %w[type]) end c.sub_location path: 'm:subLocation' do |s| with_attributes(s, Mods::LANG_ATTRIBS) end c.shelf_locator path: 'm:shelfLocator' do |s| with_attributes(s, Mods::LANG_ATTRIBS) end c.electronic_locator path: 'm:electronicLocator' c.note path: 'm:note' do |note| with_attributes(note, Mods::LANG_ATTRIBS | %w[displayLabel type]) end c.enumeration_and_chronology path: 'm:enumerationAndChronology' do |e| with_attributes(e, Mods::LANG_ATTRIBS | %w[unitType]) end c.item_identifier path: 'm:itemIdentifier' do |i| with_attributes(i, %w[type]) end end end n.holdingExternal :path => 'm:holdingExternal' end # t.location # NAME ------------------------------------------------------------------------------------ t.plain_name :path => '/m:mods/m:name' t._plain_name :path => '(//m:name|//m:alternativeName)' do |n| with_attributes(n, Mods::Name::ATTRIBUTES) # elements n.namePart :path => 'm:namePart' do |np| with_attributes(np, %w[type]) end n.family_name :path => 'm:namePart[@type="family"]' n.given_name :path => 'm:namePart[@type="given"]' n.termsOfAddress :path => 'm:namePart[@type="termsOfAddress"]' n.date :path => 'm:namePart[@type="date"]' n.alternative_name :path => 'm:alternativeName' do |alt| with_attributes(alt, %w[altType]) end n.displayForm :path => 'm:displayForm' n.affiliation :path => 'm:affiliation' n.nameIdentifier :path => 'm:nameIdentifier' do |ni| with_attributes(ni, Mods::LANG_ATTRIBS | %w[displayLabel type typeURI invalid]) end n.description_el :path => 'm:description' # description is used by Nokogiri n.role :path => 'm:role' do |r| r.roleTerm :path => 'm:roleTerm' do |rt| with_attributes(rt, Mods::AUTHORITY_ATTRIBS | %w[type]) rt.value path: '.', single: true, accessor: (lambda do |roleTerm| text = roleTerm.text.strip if roleTerm.type_at == 'code' && roleTerm. == 'marcrelator' MARC_RELATOR.fetch(text, text) else text end end) end # role convenience method r. :path => '.', :accessor => lambda { |role_node| role_node.roleTerm..first } # role convenience method r.code :path => '.', :accessor => lambda { |role_node| role_node.roleTerm.select { |role_t| role_t.type_at == 'code' }.first&.text } # role convenience method r.value :path => '.', :accessor => lambda { |role_node| val = role_node.roleTerm.select { |role_t| role_t.type_at == 'text' }.first&.text val || role_node.roleTerm.select { |role_t| role_t.type_at == 'code' && role_t..match?(/marcrelator/) }.first&.value } end # role node # name convenience method # uses the displayForm of a name if present # if no displayForm, try to make a string from family, given and terms of address # otherwise, return all non-date nameParts concatenated together n.display_value :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' if name_node.displayForm && name_node.displayForm.text.size > 0 dv = name_node.displayForm.text end if dv.empty? if name_node.type_at == 'personal' if name_node.family_name.size > 0 dv = name_node.given_name.size > 0 ? "#{name_node.family_name.text}, #{name_node.given_name.text}" : name_node.family_name.text elsif name_node.given_name.size > 0 dv = name_node.given_name.text end if !dv.empty? first = true name_node.namePart.each { |np| if np.type_at == 'termsOfAddress' && !np.text.empty? if first dv = dv + " " + np.text first = false else dv = dv + ", " + np.text end end } else # no family or given name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end else # not a personal name dv = name_node.namePart.select {|np| np.type_at != 'date' && !np.text.empty?}.join(" ") end end dv.strip.empty? ? nil : dv.strip } # name convenience method n.display_value_w_date :path => '.', :single => true, :accessor => lambda {|name_node| dv = '' dv = dv + name_node.display_value if name_node.display_value name_node.namePart.each { |np| if np.type_at == 'date' && !np.text.empty? && !dv.end_with?(np.text) dv = dv + ", #{np.text}" end } if dv.start_with?(', ') dv.sub(', ', '') end dv.strip.empty? ? nil : dv.strip } end # t._plain_name t.personal_name :path => '/m:mods/m:name[@type="personal"]' t._personal_name :path => '//m:name[@type="personal"]' t.corporate_name :path => '/m:mods/m:name[@type="corporate"]' t._corporate_name :path => '//m:name[@type="corporate"]' t.conference_name :path => '/m:mods/m:name[@type="conference"]' t._conference_name :path => '//m:name[@type="conference"]' # NOTE --------------------------------------------------------------------------------- t.note :path => '/m:mods/m:note' t._note :path => '//m:note' do |n| with_attributes(n, Mods::LANG_ATTRIBS | %w[ID displayLabel type]) end # ORIGIN_INFO -------------------------------------------------------------------------- t.origin_info :path => '/m:mods/m:originInfo' t._origin_info :path => '//m:originInfo' do |n| n.as_object :path => '.', :accessor => lambda { |a| Mods::OriginInfo.new(a) } # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.place :path => 'm:place' do |e| e.placeTerm :path => 'm:placeTerm' do |ee| with_attributes(ee, Mods::AUTHORITY_ATTRIBS | %w[type]) end end n.publisher :path => 'm:publisher' Mods::OriginInfo::DATE_ELEMENTS.each { |date_el| n.send date_el, :path => "m:#{date_el}" do |d| d.as_object :path => '.', :single => true, :accessor => lambda { |a| Mods::Date.from_element(a) } with_attributes(d, Mods::DATE_ATTRIBS) with_attributes(d, %w[type]) if date_el == 'dateOther' end } n.edition :path => 'm:edition' n.issuance :path => 'm:issuance' n.frequency :path => 'm:frequency' do |f| with_attributes(f, Mods::AUTHORITY_ATTRIBS) end end # t.origin_info # PART ----------------------------------------------------------------------------------- t.part :path => '/m:mods/m:part' t._part :path => '//m:part' do |n| # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[ID order type displayLabel]) # child elements n.detail :path => 'm:detail' do |e| # attributes with_attributes(e, %w[level type]) # elements e.number :path => 'm:number' e. :path => 'm:caption' e.title :path => 'm:title' end n.extent :path => 'm:extent' do |e| # TODO: extent is ordered in xml schema # attributes with_attributes(e, %w[unit]) # elements e.start :path => 'm:start' e.end :path => 'm:end' e.total :path => 'm:total' e.list :path => 'm:list' end n.date :path => 'm:date' do |e| with_attributes(e, Mods::DATE_ATTRIBS - ['keyDate']) end n.text_el :path => 'm:text' do |e| with_attributes(e, %w[displayLabel type]) end end # t._part # PHYSICAL_DESCRIPTION ------------------------------------------------------------------- t.physical_description :path => '/m:mods/m:physicalDescription' t._physical_description :path => '//m:physicalDescription' do |n| # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.digitalOrigin :path => 'm:digitalOrigin' n.extent :path => 'm:extent' n.form :path => 'm:form' do |f| with_attributes(f, Mods::AUTHORITY_ATTRIBS | %w[type]) end n.internetMediaType :path => 'm:internetMediaType' n.note :path => 'm:note' do |nn| with_attributes(nn, %w[displayLabel type]) end n.reformattingQuality :path => 'm:reformattingQuality' end # RECORD_INFO -------------------------------------------------------------------------- t.record_info :path => '/m:mods/m:recordInfo' t._record_info :path => '//m:recordInfo' do |n| # attributes with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.recordContentSource :path => 'm:recordContentSource' do |r| with_attributes(r, Mods::AUTHORITY_ATTRIBS) end n.recordCreationDate :path => 'm:recordCreationDate' do |r| with_attributes(r, Mods::DATE_ATTRIBS) end n.recordChangeDate :path => 'm:recordChangeDate' do |r| with_attributes(r, Mods::DATE_ATTRIBS) end n.recordIdentifier :path => 'm:recordIdentifier' do |r| with_attributes(r, ['source']) end n.recordOrigin :path => 'm:recordOrigin' n.languageOfCataloging :path => 'm:languageOfCataloging' do |r| with_attributes(r, Mods::AUTHORITY_ATTRIBS) r.languageTerm :path => 'm:languageTerm' r.scriptTerm :path => 'm:scriptTerm' end n.descriptionStandard :path => 'm:descriptionStandard' do |r| with_attributes(r, Mods::AUTHORITY_ATTRIBS) end end # t._record_info # RELATED_ITEM------------------------------------------------------------------------- t. :path => '/m:mods/m:relatedItem' do |n| # attributes with_attributes(n, %w[ID displayLabel type]) # elements n.abstract :path => 'm:abstract' n.accessCondition :path => 'm:accessCondition' n.classification :path => 'm:classification' n.extension :path => 'm:extension' n.genre :path => 'm:genre' n.identifier :path => 'm:identifier' n.language :path => 'm:language' n.location :path => 'm:location' n.name_el :path => 'm:name' # Note: 'name' is used by Nokogiri n.personal_name :path => 'm:name[@type="personal"]' n.corporate_name :path => 'm:name[@type="corporate"]' n.conference_name :path => 'm:name[@type="conference"]' n.note :path => 'm:note' n.originInfo :path => 'm:originInfo' n.part :path => 'm:part' n.physicalDescription :path => 'm:physicalDescription' n.recordInfo :path => 'm:recordInfo' n.subject :path => 'm:subject' n.tableOfContents :path => 'm:tableOfContents' n.targetAudience :path => 'm:targetAudience' n.titleInfo :path => 'm:titleInfo' n.typeOfResource :path => 'm:typeOfResource' end # SUBJECT ----------------------------------------------------------------------------- t.subject :path => '/m:mods/m:subject' t._subject :path => '//m:subject' do |n| # attributes with_attributes(n, Mods::AUTHORITY_ATTRIBS | Mods::LANG_ATTRIBS | %w[displayLabel]) # child elements n.cartographics :path => 'm:cartographics' do |n1| n1.scale :path => 'm:scale' n1.projection :path => 'm:projection' n1.coordinates :path => 'm:coordinates' Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "m:#{elname}" } end n.genre :path => 'm:genre' do |n1| with_attributes(n1, Mods::AUTHORITY_ATTRIBS) end n.geographic :path => 'm:geographic' do |n1| with_attributes(n1, Mods::AUTHORITY_ATTRIBS) end n.geographicCode :path => 'm:geographicCode' do |gc| with_attributes(gc, Mods::AUTHORITY_ATTRIBS) # convenience method gc.translated_value :path => '.', :accessor => lambda { |gc_node| code_val ||= gc_node.text xval = nil if code_val case gc_node. when 'marcgac' xval = MARC_GEOGRAPHIC_AREA[code_val] when 'marccountry' xval = MARC_COUNTRY[code_val] end end xval } end n.hierarchicalGeographic :path => 'm:hierarchicalGeographic' do |n1| Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname| n1.send elname, :path => "m:#{elname}" } with_attributes(n1, Mods::AUTHORITY_ATTRIBS) end # Note: 'name' is used by Nokogiri n.name_el :path => 'm:name' do |t1| with_attributes(t1, Mods::AUTHORITY_ATTRIBS) end n.personal_name :path => 'm:name[@type="personal"]' n.corporate_name :path => 'm:name[@type="corporate"]' n.conference_name :path => 'm:name[@type="conference"]' n.occupation :path => 'm:occupation' do |n1| with_attributes(n1, Mods::AUTHORITY_ATTRIBS) end n.temporal :path => 'm:temporal' do |n1| with_attributes(n1, Mods::AUTHORITY_ATTRIBS | Mods::DATE_ATTRIBS) end n.titleInfo :path => 'm:titleInfo' do |t1| with_attributes(t1, Mods::AUTHORITY_ATTRIBS) end n.topic :path => 'm:topic' do |n1| with_attributes(n1, Mods::AUTHORITY_ATTRIBS) end end # t.subject # TABLE_OF_CONTENTS --------------------------------------------------------------------- t.tableOfContents :path => '/m:mods/m:tableOfContents' t._tableOfContents :path => '//m:tableOfContents' do |n| with_attributes(n, Mods::LANG_ATTRIBS | %w[displayLabel shareable type]) end # TARGET_AUDIENCE ----------------------------------------------------------------------- t.targetAudience :path => '/m:mods/m:targetAudience' t._targetAudience :path => '//m:targetAudience' do |n| with_attributes(n, Mods::AUTHORITY_ATTRIBS | Mods::LANG_ATTRIBS | %w[displayLabel]) end # TITLE_INFO ---------------------------------------------------------------------------- t.title_info :path => '/m:mods/m:titleInfo' t._title_info :path => '//m:titleInfo' do |n| with_attributes(n, Mods::TitleInfo::ATTRIBUTES) n.title :path => 'm:title' n.subTitle :path => 'm:subTitle' n.nonSort :path => 'm:nonSort' n.partNumber :path => 'm:partNumber' n.partName :path => 'm:partName' # convenience method n.sort_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" || (node.type_at == "alternative" && mods_ng_xml.xpath('/m:mods/m:titleInfo', {'m' => Mods::MODS_NS}).size == 1) node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) end } # convenience method n.full_title :path => '.', :accessor => lambda { |node| (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" ) } # convenience method n.short_title :path => '.', :accessor => lambda { |node| if node.type_at != "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } # convenience method n.alternative_title :path => '.', :accessor => lambda { |node| if node.type_at == "alternative" (!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) + node.title.text end } end # t._title_info # TYPE_OF_RESOURCE -------------------------------------------------------------------- t.typeOfResource :path => '/m:mods/m:typeOfResource' t._typeOfResource :path => '//m:typeOfResource' do |n| with_attributes(n, %w[collection displayLabel manuscript usage]) end end mods_ng_xml.nom! mods_ng_xml end |
#short_titles ⇒ Object
Returns Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ‘ ’ + <title> elements but not including any titleInfo elements with type=“alternative”.
126 127 128 |
# File 'lib/mods/record.rb', line 126 def short_titles @mods_ng_xml.title_info.short_title.map { |n| n } end |
#sort_title ⇒ Object
Returns String containing sortable title for this mods record.
141 142 143 |
# File 'lib/mods/record.rb', line 141 def sort_title @mods_ng_xml.title_info.sort_title.find { |n| !n.nil? } end |
#term_value(messages, sep = ' ') ⇒ String
get the value for the terms, as a String. f there are multiple values, they will be joined with the separator.
If there are no values, the result will be nil.
78 79 80 81 82 |
# File 'lib/mods/record.rb', line 78 def term_value , sep = ' ' vals = term_values return nil if !vals val = vals.join sep end |
#term_values(messages) ⇒ Array<String>
get the values for the terms, as an Array. If there are no values, the result will be nil.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mods/record.rb', line 89 def term_values case when Symbol nodes = send() when String nodes = send(.to_sym) when Array obj = self .each { |msg| if msg.is_a? Symbol obj = obj.send(msg) elsif msg.is_a? String obj = obj.send(msg.to_sym) else raise ArgumentError, "term_values called with Array containing unrecognized class: #{msg.class}, #{.inspect}", caller end } nodes = obj else raise ArgumentError, "term_values called with unrecognized argument class: #{.class}", caller end vals = [] if nodes nodes.each { |n| vals << n.text unless n.text.empty? } end return nil if vals.empty? vals rescue NoMethodError raise ArgumentError, "term_values called with unknown argument: #{.inspect}", caller end |
#with_attributes(element, attributes = [], method_mappings: { 'type' => 'type_at', 'ID' => 'id_at' }) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/mods/nom_terminology.rb', line 19 def with_attributes(element, attributes = [], method_mappings: { 'type' => 'type_at', 'ID' => 'id_at' }) attributes.each do |attr_name| attr_method = method_mappings.fetch(attr_name, attr_name) element.send attr_method, path: "@#{attr_name}", accessor: lambda { |a| a.text } end end |