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

pulibrary / lsp-data / 6fc56160-a2f6-41e2-adb2-6f0cf4704a9d

17 Sep 2025 03:28PM UTC coverage: 99.594% (-0.4%) from 100.0%
6fc56160-a2f6-41e2-adb2-6f0cf4704a9d

Pull #122

circleci

mzelesky
parse figgy report
Pull Request #122: parse figgy report

55 of 59 new or added lines in 4 files covered. (93.22%)

981 of 985 relevant lines covered (99.59%)

4.67 hits per line

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

91.84
/lib/lsp-data/figgy_digital_object.rb
1
# frozen_string_literal: true
2

3
module LspData
1✔
4
  ### Transform a hash derived from the Figgy report into an object with the following
5
  ###   mandatory features:
6
  ###    1. Visibility (princeton, open, reading room, private, on campus) (taken from the visibility label)
7
  ###    2. MMS ID (key of the hash)
8
  ###    3. IIIF Manifest URL
9
  ### If the visibility is open, retrieve the metadata from the manifest and add
10
  ###   the following features:
11
  ###     1. Label
12
  ###     2. ARK
13
  ###     3. Thumbnail URL
14
  ###     4. Collections
15
  class FiggyDigitalObject
1✔
16
    attr_reader :mms_id, :visibility, :manifest_url, :conn,
1✔
17
                :manifest_identifier, :manifest_unique_portion
18

19
    def initialize(manifest_info:, mms_id:, conn:)
1✔
20
      @visibility = manifest_info['visibility']['label']
8✔
21
      @manifest_url = manifest_info['iiif_manifest_url']
8✔
22
      @manifest_unique_portion = manifest_url.gsub(%r{^.*concern/([^/]+/[^/]+)/.*$}, '\1')
8✔
23
      @manifest_identifier ||= identifier_from_manifest_url
8✔
24
      @mms_id = mms_id
8✔
25
      @conn = conn
8✔
26
      @manifest_metadata = manifest_metadata
8✔
27
    end
28

29
    def manifest_metadata
1✔
30
      return @manifest_metadata if defined?(@manifest_metadata)
15✔
31

32
      all_metadata = manifest
8✔
33
      return @manifest_metadata = nil if all_metadata.nil?
8✔
34

35
      body = all_metadata[:body]
2✔
36
      @manifest_metadata = metadata_from_manifest(body)
2✔
37
    end
38

39
    private
1✔
40

41
    def metadata_from_manifest(body)
1✔
42
      {
43
        ark: ark(body),
2✔
44
        thumbnail: thumbnail(body),
45
        label: label(body),
46
        collections: collections(body)
47
      }
48
    end
49

50
    def identifier_from_manifest_url
1✔
51
      manifest_unique_portion.gsub(%r{^[^/]+/([^/]+)$}, '\1')
8✔
52
    end
53

54
    def label(body)
1✔
55
      if body['label'].instance_of?(String)
2✔
NEW
56
        body['label']
×
57
      else
58
        body['label']['eng'].first
2✔
59
      end
60
    end
61

62
    def thumbnail(body)
1✔
63
      if body['thumbnail'].instance_of?(Array)
2✔
64
        body['thumbnail'].find { |object| object['format'] == 'image/jpeg' }['id']
4✔
65
      else
NEW
66
        body['thumbnail']['@id']
×
67
      end
68
    end
69

70
    def ark(body)
1✔
71
      if body['rendering'].instance_of?(Array)
2✔
72
        body['rendering'].find { |object| object['format'] == 'text/html' }['id']
6✔
73
      else
NEW
74
        body['rendering']['@id']
×
75
      end
76
    end
77

78
    def collections(body)
1✔
79
      english_label = body['metadata'].find { |object| object['label']['eng']&.include?('Member Of Collections') }
4✔
80
      if english_label
2✔
81
        english_label['value']['eng']
2✔
82
      else
NEW
83
        body['metadata'].find { |object| object['label'] == 'Member Of Collections' }&.[]('value')
×
84
      end
85
    end
86

87
    ### Figgy does not return the body in JSON format if the status is not 200
88
    def manifest
1✔
89
      return unless visibility == 'open'
8✔
90

91
      response = api_call
2✔
92
      return unless response.status == 200
2✔
93

94
      parse_api_response(response)
2✔
95
    end
96

97
    def api_call
1✔
98
      conn.get do |req|
2✔
99
        req.url "#{manifest_unique_portion}/manifest"
2✔
100
        req.headers['Content-Type'] = 'application/json'
2✔
101
        req.headers['Accept'] = 'application/json'
2✔
102
      end
103
    end
104
  end
105
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