class CFF::Index
Index
is the core data structure for a CITATION.cff file. It can be accessed direcly, or via File
.
Index
implements all of the fields listed in the CFF standard. Complex fields - authors
, contact
, identifiers
, keywords
, preferred-citation
, references
and type
- are documented below. All other fields are simple strings and can be set as such. A field which has not been set will return the empty string. The simple fields are (with defaults in parentheses):
-
abstract
-
cff_version
-
commit
-
date_released
- Note: returns aDate
object -
doi
-
license
-
license_url
-
message
(If you use this software in your work, please cite it using the following metadata) -
repository
-
repository_artifact
-
repository_code
-
title
-
url
-
version
Constants
Public Class Methods
Initialize a new Index
with the supplied title.
# File lib/cff/index.rb, line 77 def initialize(param) super() if param.is_a?(Hash) @fields = build_index(param) else @fields = {} @fields['cff-version'] = DEFAULT_SPEC_VERSION @fields['message'] = DEFAULT_MESSAGE @fields['title'] = param end %w[authors contact identifiers keywords references].each do |field| @fields[field] = [] if @fields[field].nil? || @fields[field].empty? end yield self if block_given? end
With no associated block, Index.open
is a synonym for ::read
. If the optional code block is given, it will be passed the parsed index as an argument and the Index
will be returned when the block terminates.
# File lib/cff/index.rb, line 111 def self.open(index) cff = Index.read(index) yield cff if block_given? cff end
Public Instance Methods
Return the list of identifiers for this citation. To add a identifier to the list, use:
index.identifiers << identifier
# File lib/cff/index.rb, line 214
Replace the list of identifiers for this citation.
# File lib/cff/index.rb, line 226
Return the list of keywords for this citation. To add a keyword to the list, use:
index.keywords << keyword
Keywords will be converted to Strings on output.
# File lib/cff/index.rb, line 233
Replace the list of keywords for this citation.
Keywords will be converted to Strings on output.
# File lib/cff/index.rb, line 247
Return the preferred citation for this citation.
# File lib/cff/index.rb, line 256
Replace the preferred citation for this citation.
# File lib/cff/index.rb, line 263
Return the list of references for this citation. To add a reference to the list, use:
index.references << reference
# File lib/cff/index.rb, line 270
Replace the list of references for this citation.
# File lib/cff/index.rb, line 282