Module: ASpaceExport::Utils

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

Class Method Summary collapse

Class Method Details

.extract_note_text(note, include_unpublished = false, add_punct = false) ⇒ Object

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'backend/app/exporters/lib/utils.rb', line 8

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

  # ANW-654: Check if last character of the note_text is terminal punctuation.
  # If not, append a period to the end of the note.
  if add_punct == true && !note_text.empty? && !['.', '!', '?'].include?(note_text[-1])
    note_text << "."
  end

  return note_text
end

.has_html?(text) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.has_xml_node?(node, text) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'backend/app/exporters/lib/utils.rb', line 28

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

.headless_note?(note_type, content) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'backend/app/exporters/lib/utils.rb', line 50

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

.headless_notesObject

some notes don’t allow heads….



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

def self.headless_notes
  %w{ legalstatus }
end

.include_p?(note_type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.notes_with_pObject

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



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

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