• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / fa8448dd-0600-47e7-8889-1dfa562d11f0

05 Sep 2023 08:01PM UTC coverage: 86.172% (-4.9%) from 91.048%
fa8448dd-0600-47e7-8889-1dfa562d11f0

push

circleci

sandbergja
i2239: Use SRU instead of Alma API for bib record retrieval

8 of 8 new or added lines in 2 files covered. (100.0%)

3309 of 3840 relevant lines covered (86.17%)

326.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.63
/app/controllers/concerns/formatting_concern.rb
1
module FormattingConcern
1✔
2
  extend ActiveSupport::Concern
1✔
3
  # @param records [MARC::Record] Could be one or a collection
4
  # @return [String] A serialized <mrx:record/> or <mrx:collection/>
5
  # "Cleans" the record of invalid xml characters
6
  def records_to_xml_string(records)
1✔
7
    if records.kind_of? Array
1✔
8
      xml_str = ''
×
9
      StringIO.open(xml_str) do |io|
×
10
        writer = MARC::XMLWriter.new(io)
×
11
        records.each do |r|
×
12
          writer.write(r) unless r.nil?
×
13
        end
14
        writer.close()
×
15
      end
16
      valid_xml(xml_str)
×
17
    elsif records.kind_of? String
1✔
18
      # example response from /almaws/v1/bibs/{mms_id}/holdings
19
      valid_xml(records)
1✔
20
    else
21
      valid_xml(records.to_xml.to_s)
×
22
    end
23
  end
24

25
  # Moved from voyager-helpers
26
  # strips invalid xml characters to prevent parsing errors
27
  # only used for "cleaning" individually retrieved records
28
  def valid_xml(xml_string)
1✔
29
    invalid_xml_range = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD]/
1✔
30
    xml_string.gsub(invalid_xml_range, '')
1✔
31
  end
32

33
  # Clean up character encoding problems by passing the
34
  # records through an XML parser
35
  # @param records [MARC::Record] Could be one or a collection
36
  # @return [Hash] If only one record was passed
37
  # @return [Array<Hash>]
38
  def pass_records_through_xml_parser(records)
1✔
39
    reader = MARC::XMLReader.new(StringIO.new(records_to_xml_string(records)))
×
40
    record_hashes = []
×
41
    reader.each { |r| record_hashes << r.to_hash }
×
42
    if record_hashes.length == 1
×
43
      record_hashes.first
×
44
    else
45
      record_hashes
×
46
    end
47
  end
48

49
  def valid_barcode?(barcode)
1✔
50
    (barcode =~ /^(32101[0-9]{9}|PULTST[0-9]{5})$/) == 0
6✔
51
  end
52

53
  def statuses_to_xml(data)
1✔
54
    # yep!
55
    s = []
×
56
    s << '<statuses>'
×
57
    data.each { |k, v| s << %(<status code="#{k}" label="#{v}" />) }
×
58
    s << '</statuses>'
×
59
    s.join('')
×
60
  end
61
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc