Module: ASpaceExport::Utils

Defined in:
backend/app/exporters/lib/utils.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) extract_note_text(note, include_unpublished = false)

Extract a string of a note’s content (including the content field and any text subnotes)



8
9
10
11
12
13
14
# File 'backend/app/exporters/lib/utils.rb', line 8

def self.extract_note_text(note, include_unpublished = false)
  subnotes = note['subnotes'] || []
  (Array(note['content']) +
   subnotes.map { |sn|
     sn['content'] if (sn['jsonmodel_type'] == 'note_text' && include_unpublished || sn["publish"])
   }.compact).join(" ")
end

+ (Boolean) has_html?(text)

Returns:

  • (Boolean)


16
17
18
# File 'backend/app/exporters/lib/utils.rb', line 16

def self.has_html?(text)
  !!(text =~ /.*\<[^>]+>.*/   )
end

+ (Boolean) has_xml_node?(node, text)

Returns:

  • (Boolean)


20
21
22
# File 'backend/app/exporters/lib/utils.rb', line 20

def self.has_xml_node?(node, text)
  !!(text =~  /\<#{node}*/ ) 
end

+ (Boolean) headless_note?(note_type, content)

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'backend/app/exporters/lib/utils.rb', line 42

def self.headless_note?(note_type, content)
   if content.strip.start_with?('<head') or self.headless_notes.include?(note_type)
      true
   else
     false
   end
end

+ (Object) headless_notes

some notes don’t allow heads….



25
26
27
# File 'backend/app/exporters/lib/utils.rb', line 25

def self.headless_notes
 %w{ legalstatus } 
end

+ (Boolean) include_p?(note_type)

Returns:

  • (Boolean)


38
39
40
# File 'backend/app/exporters/lib/utils.rb', line 38

def self.include_p?(note_type)
  self.notes_with_p.include?(note_type)
end

+ (Object) notes_with_p

… and some notes don’t allow p’s.



30
31
32
33
34
35
36
# File 'backend/app/exporters/lib/utils.rb', line 30

def self.notes_with_p
  %w{ accessrestrict accruals acqinfo altformavail appraisal arrangement 
  bibliography bioghist blockquote controlaccess custodhist daodesc descgrp 
  div dsc dscgrp editionstmt fileplan index note odd originalsloc otherfindaid 
  phystech prefercite processinfo publicationstmt relatedmaterial scopecontent 
  separatedmaterial seriesstmt titlepage userestrict }
end