Top Level Namespace

Defined Under Namespace

Modules: FspHarvester, HarvesterTools

Instance Method Summary collapse

Instance Method Details

#check_describedby_rules(describedby:, metadata:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/signposting_tests.rb', line 20

def check_describedby_rules(describedby:, metadata:)
  @meta = 
  describedby.each do |l|
    unless l.respond_to? 'type'
      @meta.add_warning(['005', l.href, ''])
      @meta.comments << "WARN: The resource does not follow the FAIR Signposting standard, which requires any describedby links to also have a 'type' attribute.\n"
    end
    type = l.type if l.respond_to? 'type'
    type ||= '*/*'
    header = { accept: type }
    response = HarvesterTools::WebUtils.fspfetch(url: l.href, headers: header, method: :head)
    if response
      responsetype = response.headers[:content_type]
      @meta.comments << "INFO: describedby link responds with content type #{responsetype}\n"
      if responsetype =~ %r{^(.*/[^;]+)}
        responsetype = Regexp.last_match(1).to_s # remove the e.g. charset information
      end
      @meta.comments << "INFO: testing content type |#{responsetype}| against |#{type}|\n"
      if type != '*/*'
        if responsetype == type
          @meta.comments << "INFO: describedby link responds according to Signposting specifications\n"
        else
          @meta.add_warning(['009', l.href, header])
          @meta.comments << "WARN: Content type of returned describedby link #{responsetype}does not match the 'type' attribute #{type}\n"
        end
      else
        @meta.add_warning(['010', l.href, header])
        @meta.comments << "WARN: Content type of returned describedby link is not specified in response headers or cannot be matched against accept headers\n"
      end
    else
      @meta.add_warning(['008', l.href, header])
      @meta.comments << "WARN: describedby link doesn't resolve\n"
    end
  end
end

#check_for_citeas_conflicts(citeas:, metadata:) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/signposting_tests.rb', line 1

def check_for_citeas_conflicts(citeas:, metadata: )
  @meta = 
  @meta.comments << 'INFO: checking for conflicting cite-as links'
  citeas_hrefs = Hash.new
  citeas.each do |link|
    warn "INFO: Adding citeas #{link.href} to the testing queue."
    @meta.comments << "INFO: Adding citeas #{link.href} to the testing queue."
    citeas_hrefs[link.href] = link
  end
#warn "finalhash #{citeas_hrefs}"
  if citeas_hrefs.length > 1
    @meta.comments << 'INFO: Found multiple non-identical cite-as links.'
    @meta.add_warning(['007', '', ''])
    @meta.comments << "WARN: The resource does not follow the FAIR Signposting standard: Found conflicting cite-as link headers.\n"
  end
  citeas_hrefs.values  # return list of unique links
end

#check_item_rules(item:, metadata:) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/signposting_tests.rb', line 56

def check_item_rules(item:, metadata:)
  @meta = 
  item.each do |l| # l = LinkHeaders::Link
    unless l.respond_to? 'type'
      @meta.add_warning(['011', l.href, ''])
      @meta.comments << "WARN: The resource does not follow the FAIR Signposting standard, which encourages any item links to also have a 'type' attribute.\n"
    end
    type = l.type if l.respond_to? 'type'
    type ||= '*/*' # this becomes a frozen string
    header = { accept: type }
    response = HarvesterTools::WebUtils.fspfetch(url: l.href, headers: header, method: :head)

    if response
      if response.headers[:content_type] and type != '*/*'
        rtype = type.gsub(%r{/}, "\/")   # because type is a frozen string
        rtype = rtype.gsub(/\+/, '.')
        typeregex = Regexp.new(type)
        if response.headers[:content_type].match(typeregex)
          warn response.headers[:content_type]
          warn typeregex.inspect
          @meta.comments << "INFO: item link responds according to Signposting specifications\n"
        else
          @meta.add_warning(['012', l.href, header])
          @meta.comments << "WARN: Content type of returned item link does not match the 'type' attribute\n"
        end
      else
        @meta.add_warning(['013', l.href, header])
        @meta.comments << "WARN: Content type of returned item link is not specified in response headers or cannot be matched against accept headers\n"
      end
    else
      @meta.add_warning(['014', l.href, header])
      @meta.comments << "WARN: item link doesn't resolve\n"
    end
  end
end