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):

Constants

DEFAULT_MESSAGE

The default message to use if none is explicitly set.

MODEL_TYPES

The allowed CFF types.

Public Class Methods

new(title) → Index click to toggle source
new(title) { |index| block } → Index

Initialize a new Index with the supplied title.

Calls superclass method
# 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
open(String) → Index click to toggle source
open(String) { |cff| block } → Index

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
read(String) → Index click to toggle source

Read a CFF Index from a String and parse it for subsequent manipulation.

# File lib/cff/index.rb, line 100
def self.read(index)
  new(Util.parse_yaml(index))
end

Public Instance Methods

authors → Array click to toggle source

Return the list of authors for this citation. To add an author to the list, use:

index.authors << author

Authors can be a Person or Entity.

# File lib/cff/index.rb, line 168
    
authors = array_of_authors → Array click to toggle source

Replace the list of authors for this citation.

Authors can be a Person or Entity.

# File lib/cff/index.rb, line 182
    
contact → Array click to toggle source

Return the list of contacts for this citation. To add a contact to the list, use:

index.contact << contact

Contacts can be a Person or Entity.

# File lib/cff/index.rb, line 191
    
contact = array_of_contacts → Array click to toggle source

Replace the list of contacts for this citation.

Contacts can be a Person or Entity.

# File lib/cff/index.rb, line 205
    
identifiers → Array click to toggle source

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
    
identifiers = array_of_identifiers → Array click to toggle source

Replace the list of identifiers for this citation.

# File lib/cff/index.rb, line 226
    
keywords → Array click to toggle source

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
    
keywords = array_of_keywords → Array click to toggle source

Replace the list of keywords for this citation.

Keywords will be converted to Strings on output.

# File lib/cff/index.rb, line 247
    
preferred_citation → Reference click to toggle source

Return the preferred citation for this citation.

# File lib/cff/index.rb, line 256
    
preferred_citation = Reference click to toggle source

Replace the preferred citation for this citation.

# File lib/cff/index.rb, line 263
    
references → Array click to toggle source

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
    
references = array_of_references → Array click to toggle source

Replace the list of references for this citation.

# File lib/cff/index.rb, line 282
  
type = type click to toggle source

Sets the type of this CFF Index. The type is currently restricted to one of software or dataset. If this field is not set then you should assume that the type is software.

# File lib/cff/index.rb, line 125
def type=(type)
  type = type.downcase
  @fields['type'] = type if MODEL_TYPES.include?(type)
end