Class: BEL::Nanopub::Metadata
- Inherits:
-
Object
- Object
- BEL::Nanopub::Metadata
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/bel/nanopub/metadata.rb
Constant Summary collapse
- BEL_VERSION =
:bel_version
- DOCUMENT_HEADER =
:document_header
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #bel_version ⇒ Object
- #bel_version=(bel_version) ⇒ Object
- #document_header ⇒ Object
- #document_header=(document_header) ⇒ Object
-
#initialize(values = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #to_a ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ Metadata
Returns a new instance of Metadata.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bel/nanopub/metadata.rb', line 15 def initialize(values = {}) if values.is_a? Array @values = Hash[ values.map { |item| name = item[:name] || item['name'] value = item[:value] || item['value'] [name.to_sym, value] } ] else @values = values end doc_hdr = @values[:document_header] unless doc_hdr.nil? @values[:document_header] = Hash[ doc_hdr.map { |item| [item[0].to_sym, item[1]] } ] end unless @values.key?(:bel_version) @values[:bel_version] = BELParser::Language.default_version end header = @values[:document_header] unless header.nil? = header[:Authors] unless .is_a? Array = [] header[:Authors] = end licenses = header[:Licenses] unless licenses.is_a? Array licenses = [licenses] header[:Licenses] = licenses end end end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
7 8 9 |
# File 'lib/bel/nanopub/metadata.rb', line 7 def values @values end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
83 84 85 86 |
# File 'lib/bel/nanopub/metadata.rb', line 83 def ==(other) return false if other.nil? @values == other.values end |
#bel_version ⇒ Object
57 58 59 |
# File 'lib/bel/nanopub/metadata.rb', line 57 def bel_version @values[BEL_VERSION] end |
#bel_version=(bel_version) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bel/nanopub/metadata.rb', line 61 def bel_version=(bel_version) @values[BEL_VERSION] = case bel_version when BELParser::Language::Specification bel_version.version.to_s when String bel_version else raise( ArgumentError, %(expected String, Specification; actual #{bel_version.class})) end end |
#document_header ⇒ Object
75 76 77 |
# File 'lib/bel/nanopub/metadata.rb', line 75 def document_header @values[DOCUMENT_HEADER] ||= {} end |
#document_header=(document_header) ⇒ Object
79 80 81 |
# File 'lib/bel/nanopub/metadata.rb', line 79 def document_header=(document_header) @values[DOCUMENT_HEADER] = document_header end |
#to_a ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/bel/nanopub/metadata.rb', line 89 def to_a @values.each_pair.map { |key, value| { name: key, value: value } } end |