Class: BEL::Nanopub::Citation
- Inherits:
-
Object
- Object
- BEL::Nanopub::Citation
- Defined in:
- lib/bel/nanopub/citation.rb
Overview
A Citation describes a cited reference which Nanopub is derived from.
Constant Summary collapse
- MEMBER_ORDER =
The ordering of citation attributes to allow processing of sequential input of citation fields.
The ordered attributes are:
%i(type name id date authors comment)
Instance Attribute Summary collapse
-
#authors ⇒ Array<String>
Returns the
Array
ofString
authors. -
#comment ⇒ String
an additional comment related to this resource.
-
#date ⇒ String
the date the resource was published.
-
#id ⇒ String
the unique identifier for the cited resource.
-
#name ⇒ String
the name of the cited resource.
-
#type ⇒ String
the type of resource the cited material appears in (e.g. PubMed, Journal, Book, Online Resource, etc…).
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(*args) ⇒ Citation
constructor
Creates a Citation object from variable arguments.
- #to_a ⇒ Object
-
#to_h ⇒ Hash
Returns a
Hash
of the citation members accoring to #MEMBER_ORDER. -
#valid? ⇒ true, false
Returns whether the citation has enough pertinent information to be considered valid.
Constructor Details
#initialize(*args) ⇒ Citation
Creates a BEL::Nanopub::Citation object from variable arguments.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bel/nanopub/citation.rb', line 53 def initialize(*args) return if !args || args.empty? if args.length == 1 enumerable = args.first if enumerable.respond_to? :each_pair enumerable.keys.each do |key| enumerable[key.to_s.to_sym] = enumerable.delete(key) end (MEMBER_ORDER & enumerable.keys).each do |member| self.send(:"#{member}=", enumerable[member]) end elsif enumerable.respond_to? :each MEMBER_ORDER.zip(enumerable.each).each do |member, value| self.send(:"#{member}=", value) end end else (MEMBER_ORDER & args).each do |member| self.send(:"#{member}=", hash[member]) end end end |
Instance Attribute Details
#authors ⇒ Array<String>
Returns the Array
of String
authors.
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def @authors end |
#comment ⇒ String
an additional comment related to this resource
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def comment @comment end |
#date ⇒ String
the date the resource was published
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def date @date end |
#id ⇒ String
the unique identifier for the cited resource. For example, a “PubMed” type should have a PMID (i.e. 12102192).
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def id @id end |
#name ⇒ String
the name of the cited resource
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def name @name end |
#type ⇒ String
the type of resource the cited material appears in (e.g. PubMed, Journal, Book, Online Resource, etc…)
14 15 16 |
# File 'lib/bel/nanopub/citation.rb', line 14 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
103 104 105 106 107 108 109 |
# File 'lib/bel/nanopub/citation.rb', line 103 def ==(other) return false if other == nil id == other.id && type == other.type && name == other.name && == other. && date == other.date && comment == other.comment end |
#hash ⇒ Object
99 100 101 |
# File 'lib/bel/nanopub/citation.rb', line 99 def hash [id, type, name, , date, comment].hash end |
#to_a ⇒ Object
122 123 124 125 126 127 |
# File 'lib/bel/nanopub/citation.rb', line 122 def to_a MEMBER_ORDER.reduce([]) { |array, member| array << self.send(member) array } end |
#to_h ⇒ Hash
Returns a Hash
of the citation members accoring to #MEMBER_ORDER.
115 116 117 118 119 120 |
# File 'lib/bel/nanopub/citation.rb', line 115 def to_h MEMBER_ORDER.reduce({}) { |hash, member| hash[member] = self.send(member) hash } end |
#valid? ⇒ true, false
Returns whether the citation has enough pertinent information to be considered valid.
95 96 97 |
# File 'lib/bel/nanopub/citation.rb', line 95 def valid? type != nil && id != nil && name != nil end |