Class: BELParser::Expression::Model::Annotation
- Inherits:
-
Object
- Object
- BELParser::Expression::Model::Annotation
- Includes:
- Enumerable
- Defined in:
- lib/bel_parser/expression/model/annotation.rb
Overview
Annotation represents a catalog of biological annotation values.
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#keyword ⇒ Object
Returns the value of attribute keyword.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri_reader ⇒ Object
Returns the value of attribute uri_reader.
-
#url_reader ⇒ Object
Returns the value of attribute url_reader.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](value) ⇒ Object
- #domain_equal?(other) ⇒ Boolean
- #each ⇒ Object
- #hash ⇒ Object
-
#initialize(keyword, type, domain, options = {}) ⇒ Annotation
constructor
A new instance of Annotation.
- #initialize_copy(original) ⇒ Object
- #to_s ⇒ Object
- #uri? ⇒ Boolean
- #url? ⇒ Boolean
Constructor Details
#initialize(keyword, type, domain, options = {}) ⇒ Annotation
Returns a new instance of Annotation.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 14 def initialize(keyword, type, domain, = {}) raise(ArgumentError, 'keyword is nil') unless keyword raise(ArgumentError, 'type is nil') unless type raise(ArgumentError, 'domain is nil') unless domain @keyword = keyword @type = type.to_sym @domain = domain # configure reader for URIs (RDF). @uri_reader = .fetch(:uri_reader, BELParser::Resource.default_uri_reader) BELParser::Resource::Reader.assert_reader(@uri_reader, 'uri_reader') # configure reader for URLs (Resource files). @url_reader = .fetch(:url_reader, BELParser::Resource.default_url_reader) BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader') end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
10 11 12 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 10 def domain @domain end |
#keyword ⇒ Object
Returns the value of attribute keyword.
8 9 10 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 8 def keyword @keyword end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 9 def type @type end |
#uri_reader ⇒ Object
Returns the value of attribute uri_reader.
11 12 13 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 11 def uri_reader @uri_reader end |
#url_reader ⇒ Object
Returns the value of attribute url_reader.
12 13 14 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 12 def url_reader @url_reader end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
90 91 92 93 94 95 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 90 def ==(other) return false if other.nil? @keyword == other.keyword && @type == other.type && @domain == other.domain end |
#[](value) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 58 def [](value) if uri? @uri_reader.retrieve_value_from_resource(@domain, value) elsif url? @url_reader.retrieve_value_from_resource(@domain, value) else nil end end |
#domain_equal?(other) ⇒ Boolean
98 99 100 101 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 98 def domain_equal?(other) return false if other.nil? @type == other.type && @domain == other.domain end |
#each ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 68 def each if block_given? values = if uri? @uri_reader.retrieve_values_from_resource(@domain) elsif url? @url_reader.retrieve_values_from_resource(@domain) else [] end values.each do |value| yield value end else to_enum(:each) end end |
#hash ⇒ Object
86 87 88 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 86 def hash [@keyword, @type, @domain].hash end |
#initialize_copy(original) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 32 def initialize_copy(original) @keyword = original.keyword @type = original.type @domain = original.domain @uri_reader = original.uri_reader @url_reader = original.url_reader end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 103 def to_s @keyword.to_s end |
#uri? ⇒ Boolean
50 51 52 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 50 def uri? @type == :uri end |
#url? ⇒ Boolean
54 55 56 |
# File 'lib/bel_parser/expression/model/annotation.rb', line 54 def url? @type == :url end |