Class: CFF::Reference

Inherits:
ModelPart show all
Defined in:
lib/cff/reference.rb

Overview

Reference provides a reference pertaining to the software version or the software itself, e.g., a software paper describing the abstract concepts of the software, a paper describing an algorithm that has been implemented in the software version, etc.

Constant Summary collapse

ALLOWED_FIELDS =
[
  'abbreviation', 'abstract', 'authors', 'collection-doi',
  'collection-title', 'collection-type', 'commit', 'conference', 'contact',
  'copyright', 'data-type', 'database', 'database-provider',
  'date-accessed', 'date-downloaded', 'date-published', 'date-released',
  'department', 'doi', 'edition', 'editors', 'editors-series', 'end',
  'entry', 'filename', 'institution', 'isbn', 'issn', 'issue', 'issue-date',
  'issue-title', 'journal', 'keywords', 'license', 'license-url', 'loc-end',
  'loc-start', 'location', 'medium', 'month', 'nihmsid', 'notes', 'number',
  'number-volumes', 'pages', 'patent-states', 'pmcid', 'publisher',
  'recipients', 'repository', 'repository-code', 'repository-artifact',
  'scope', 'section', 'senders', 'start', 'status', 'thesis-type', 'title',
  'translators', 'type', 'url', 'version', 'volume', 'volume-title', 'year',
  'year-original'
].freeze
REFERENCE_TYPES =
[
  'art', 'article', 'audiovisual', 'bill', 'blog', 'book', 'catalogue',
  'conference', 'conference-paper', 'data', 'database', 'dictionary',
  'edited-work', 'encyclopedia', 'film-broadcast', 'generic',
  'government-document', 'grant', 'hearing', 'historical-work',
  'legal-case', 'legal-rule', 'magazine-article', 'manual', 'map',
  'multimedia', 'music', 'newspaper-article', 'pamphlet', 'patent',
  'personal-communication', 'proceedings', 'report', 'serial', 'slides',
  'software', 'software-code', 'software-container', 'software-executable',
  'software-virtual-machine', 'sound-recording', 'standard', 'statute',
  'thesis', 'unpublished', 'video', 'website'
].freeze
REFERENCE_STATUS_TYPES =

The [defined set of reference status types](citation-file-format.github.io/1.0.3/specifications/#/status-strings).

[
  'abstract', 'advance-online', 'in-preparation', 'in-press',
  'pre-print', 'submitted'
].freeze

Instance Method Summary collapse

Methods inherited from ModelPart

#method_missing, #respond_to_missing?

Methods included from Util

#build_actor_collection!, #fields_to_hash, #method_to_field, #normalize_modelpart_array!

Constructor Details

#initialize(param, *more) ⇒ Reference

:call-seq:

new(title) -> Reference
new(title, type) -> Reference

Create a new Reference with the supplied title and, optionally, type. If type is not given, or is not one of the [defined set of reference types](citation-file-format.github.io/1.0.3/specifications/#/reference-types), ‘generic’ will be used by default.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cff/reference.rb', line 68

def initialize(param, *more)
  if param.is_a?(Hash)
    @fields = build_model(param)
  else
    @fields = Hash.new('')
    type = more[0] &&= more[0].downcase
    @fields['type'] = REFERENCE_TYPES.include?(type) ? type : 'generic'
    @fields['title'] = param
  end

  [
    'authors', 'contact', 'editors', 'editors-series', 'keywords',
    'patent-states', 'recipients', 'senders', 'translators'
  ].each { |field| @fields[field] = [] if @fields[field].empty? }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CFF::ModelPart

Instance Method Details

#add_language(lang) ⇒ Object

:call-seq:

add_language language

Add a language to this Reference. Input is converted to the ISO 639-3 three letter language code, so ‘GER` becomes `deu`, `french` becomes `fra` and `en` becomes `eng`.



90
91
92
93
94
95
96
# File 'lib/cff/reference.rb', line 90

def add_language(lang)
  @fields['languages'] = [] if @fields['languages'].empty?
  lang = LanguageList::LanguageInfo.find(lang)
  return if lang.nil?
  lang = lang.iso_639_3
  @fields['languages'] << lang unless @fields['languages'].include? lang
end

#date_accessed=(date) ⇒ Object

:call-seq:

date_accessed = date

Set the ‘date-accessed` field. If a non-Date object is passed in it will be parsed into a Date.



130
131
132
133
134
# File 'lib/cff/reference.rb', line 130

def date_accessed=(date)
  date = Date.parse(date) unless date.is_a?(Date)

  @fields['date-accessed'] = date
end

#date_downloaded=(date) ⇒ Object

:call-seq:

date_downloaded = date

Set the ‘date-downloaded` field. If a non-Date object is passed in it will be parsed into a Date.



141
142
143
144
145
# File 'lib/cff/reference.rb', line 141

def date_downloaded=(date)
  date = Date.parse(date) unless date.is_a?(Date)

  @fields['date-downloaded'] = date
end

#date_published=(date) ⇒ Object

:call-seq:

date_published = date

Set the ‘date-published` field. If a non-Date object is passed in it will be parsed into a Date.



152
153
154
155
156
# File 'lib/cff/reference.rb', line 152

def date_published=(date)
  date = Date.parse(date) unless date.is_a?(Date)

  @fields['date-published'] = date
end

#date_released=(date) ⇒ Object

:call-seq:

date_released = date

Set the ‘date-released` field. If a non-Date object is passed in it will be parsed into a Date.



163
164
165
166
167
# File 'lib/cff/reference.rb', line 163

def date_released=(date)
  date = Date.parse(date) unless date.is_a?(Date)

  @fields['date-released'] = date
end

#fieldsObject

Override superclass #fields as References contain model parts too.



206
207
208
209
210
211
212
213
214
215
# File 'lib/cff/reference.rb', line 206

def fields # :nodoc:
  [
    'authors', 'contact', 'editors', 'editors-series', 'recipients',
    'senders', 'translators'
  ].each do |field|
    normalize_modelpart_array!(@fields[field])
  end

  fields_to_hash(@fields)
end

#formatObject

:call-seq:

format -> String

Returns the format of this Reference.



173
174
175
# File 'lib/cff/reference.rb', line 173

def format
  @fields['format']
end

#format=(fmt) ⇒ Object

:call-seq:

format = format

Sets the format of this Reference.



181
182
183
# File 'lib/cff/reference.rb', line 181

def format=(fmt)
  @fields['format'] = fmt
end

#languagesObject

:call-seq:

languages -> Array

Return the list of languages associated with this Reference.



110
111
112
# File 'lib/cff/reference.rb', line 110

def languages
  @fields['languages'].empty? ? [] : @fields['languages'].dup
end

#license=(lic) ⇒ Object

:call-seq:

license = license

Set the license of this Reference. Only licenses that conform to the [SPDX License List](spdx.org/licenses/) will be accepted. If you need specify a different license you should set ‘license-url` with a link to the license instead.



121
122
123
# File 'lib/cff/reference.rb', line 121

def license=(lic)
  @fields['license'] = lic unless SpdxLicenses.lookup(lic).nil?
end

#reset_languagesObject

:call-seq:

reset_languages

Reset the list of languages for this Reference to be empty.



102
103
104
# File 'lib/cff/reference.rb', line 102

def reset_languages
  @fields.delete('languages')
end

#status=(status) ⇒ Object

:call-seq:

status = status

Sets the status of this Reference. The status is restricted to a [defined set of status types](citation-file-format.github.io/1.0.3/specifications/#/status-strings).



190
191
192
193
# File 'lib/cff/reference.rb', line 190

def status=(status)
  status.downcase!
  @fields['status'] = status if REFERENCE_STATUS_TYPES.include?(status)
end

#type=(type) ⇒ Object

:call-seq:

type = type

Sets the type of this Reference. The type is restricted to a [defined set of reference types](citation-file-format.github.io/1.0.3/specifications/#/reference-types).



200
201
202
203
# File 'lib/cff/reference.rb', line 200

def type=(type)
  type.downcase!
  @fields['type'] = type if REFERENCE_TYPES.include?(type)
end