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

pulibrary / lsp-data / 09bc910d-1a06-4261-b222-62a3d4c10101

08 Aug 2025 02:36PM UTC coverage: 96.706% (-3.3%) from 100.0%
09bc910d-1a06-4261-b222-62a3d4c10101

Pull #111

circleci

mzelesky
create oclc match class
Pull Request #111: create oclc match class

23 of 51 new or added lines in 3 files covered. (45.1%)

822 of 850 relevant lines covered (96.71%)

4.45 hits per line

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

41.67
/lib/lsp-data/oclc_record_match.rb
1
# frozen_string_literal: true
2

3
module LspData
1✔
4
  ### Return all matched records by a standard number identifier
5
  ###   and have a separate method to return records deemed acceptable
6
  ###   for copy cataloging
7
  ### Must provide a Z3950Connection object for OCLC
8
  ### identifier_type is either `isbn` or 'oclc'
9
  class OCLCRecordMatch
1✔
10
    attr_reader :identifier, :identifier_type, :conn
1✔
11

12
    def initialize(identifier:, identifier_type:, conn:)
1✔
NEW
13
      @identifier = identifier
×
NEW
14
      @identifier_type = identifier_type
×
NEW
15
      @conn = conn
×
16
    end
17

18
    def records
1✔
NEW
19
      search_index = case identifier_type
×
20
                     when 'isbn'
NEW
21
                       7
×
22
                     when 'oclc'
NEW
23
                       12
×
24
                     end
NEW
25
      return unless search_index
×
26

NEW
27
      result = conn.search_by_id(index: search_index, identifier: identifier)
×
NEW
28
      result.reject(&:nil?)
×
29
    end
30

31
    def filtered_records(title)
1✔
NEW
32
      all_records = records
×
NEW
33
      all_records.select { |record| acceptable_record?(record, title) }
×
34
    end
35

36
    private
1✔
37

38
    def acceptable_leader?(record)
1✔
NEW
39
      [' ', '1', '4', 'I', 'M', 'L'].include?(record.leader[17]) &&
×
40
        record.leader[6..7] == 'am'
41
    end
42

43
    def belle_lettres?(record)
1✔
NEW
44
      %w[1 d f j m p].include?(record['008'].value[33])
×
45
    end
46

47
    def acceptable_subject?(record)
1✔
NEW
48
      record.fields('600'..'655').any? { |field| field.indicator2 == '0' }
×
49
    end
50

51
    def pcc050?(record)
1✔
NEW
52
      record.fields('042').any? { |f| f['a'] == 'pcc' } && record['050']
×
53
    end
54

55
    def call_num050?(record)
1✔
NEW
56
      record.fields('050').any? { |f| f['a'] =~ /\d/ }
×
57
    end
58

59
    def dlc040?(record)
1✔
NEW
60
      record['040'] =~ /DLC/
×
61
    end
62

63
    def electronic_reproduction?(record)
1✔
NEW
64
      record.fields('006').any? { |field| field.value[0] == 'm' } ||
×
NEW
65
        record.fields('007').any? { |field| field.value[0] == 'c' } ||
×
66
        record['245']['h'] ||
67
        record['533']
68
    end
69

70
    def normalize_string(string)
1✔
NEW
71
      strip_punctuation(string).unicode_normalize(:nfd)
×
72
                               .gsub(/\p{InCombiningDiacriticalMarks}/, '')
73
                               .downcase
74
    end
75

76
    def strip_punctuation(string)
1✔
NEW
77
      string.gsub('%22', '')
×
78
            .gsub(/^\s*[aA]\s+/, '')
79
            .gsub(/^\s*[aA]n\s+/, '')
80
            .gsub(/^\s*[Tt]he\s+/, '')
81
            .gsub(/['{}]/, '')
82
            .gsub('&', 'and')
83
            .gsub(/[\u0020-\u0025\u0028-\u002f]/, '')
84
            .gsub(/[\u003a-\u0040\u005b-\u0060]/, '')
85
            .gsub(/[\u007c\u007e\u00a9]/, '')
86
    end
87

88
    def process_title(title)
1✔
NEW
89
      normalized = normalize_string(title)
×
NEW
90
      "#{normalized[5..9]}#{normalized[14..18]}"
×
91
    end
92

93
    def title_match?(record, title)
1✔
NEW
94
      process_title(title)
×
NEW
95
      process_title(title) == process_title(record['245']['a'])
×
96
    end
97

98
    def acceptable_record?(record, title)
1✔
NEW
99
      acceptable_leader?(record) &&
×
100
        acceptable_f040b?(record) &&
NEW
101
        (belle_lettres?(record) || acceptable_subject?(record)) &&
×
102
        call_num050?(record) &&
103
        title_match?(record, title) &&
104
        electronic_reproduction?(record) == false
105
    end
106

107
    def acceptable_f040b?(record)
1✔
NEW
108
      record['040']['b'].nil? || record['040']['b'] == 'eng'
×
109
    end
110
  end
111
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