Skip to content

Commit

Permalink
Add support for Identifier relation types.
Browse files Browse the repository at this point in the history
These are introduced in CFF schema version 1.3.0.
  • Loading branch information
hainesr committed Feb 22, 2024
1 parent 4f5186f commit 0ab5f8b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/cff/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Identifier < ModelPart
end.freeze
end.freeze

# The defined set of identifier relation types (link to come).
IDENTIFIER_RELATION_TYPES = Schemas.read_defs('identifier-relation', 'enum') do |obj|
obj.dup.freeze
end.compact.freeze

# :call-seq:
# new -> Identifier
# new { |id| block } -> Identifier
Expand All @@ -69,6 +74,17 @@ def initialize(param = nil, value = nil)
yield self if block_given?
end

# :call-seq:
# relation = relation
#
# Sets the relation type of this Identifier. The relation is restricted to
# a defined set of identifier relation types (link to come).
#
# *Note:* This field is only available since version 1.3.0.
def relation=(relation)
@fields['relation'] = relation if IDENTIFIER_RELATION_TYPES.include?(relation)
end

# :call-seq:
# type = type
#
Expand Down
18 changes: 17 additions & 1 deletion test/identifier_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) 2018-2022 The Ruby Citation File Format Developers.
# Copyright (c) 2018-2024 The Ruby Citation File Format Developers.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,6 +72,22 @@ def test_bad_methods_not_allowed
end
end

def test_relation_type_restricted_to_allowed_types
id = ::CFF::Identifier.new

id.relation = 'IsCitedBy'
assert_equal('IsCitedBy', id.relation)

id.relation = 'xxx'
assert_equal('IsCitedBy', id.relation)

id.relation = 'compiles' # Incorrect case.
assert_equal('IsCitedBy', id.relation)

id.relation = 'Obsoletes'
assert_equal('Obsoletes', id.relation)
end

def test_type_restricted_to_allowed_types
id = ::CFF::Identifier.new

Expand Down

0 comments on commit 0ab5f8b

Please sign in to comment.