Class: BELParser::Expression::Model::Namespace
- Inherits:
-
Object
- Object
- BELParser::Expression::Model::Namespace
- Defined in:
- lib/bel_parser/expression/model/namespace.rb
Overview
Namespace represents a catalog of biological identifiers that are to identify parameter values like genes (e.g. AKT1), diseases (e.g. hypertropia), and processes (e.g. anaphase).
Instance Attribute Summary collapse
-
#keyword ⇒ Object
Returns the value of attribute keyword.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#uri_reader ⇒ Object
readonly
Returns the value of attribute uri_reader.
-
#url ⇒ Object
Returns the value of attribute url.
-
#url_reader ⇒ Object
readonly
Returns the value of attribute url_reader.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](value) ⇒ Object
- #domain ⇒ Object
- #domain_equal?(other) ⇒ Boolean
- #each ⇒ Object
- #hash ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(keyword, uri = nil, url = nil, options = {}) ⇒ Namespace
constructor
A new instance of Namespace.
- #initialize_copy(original) ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
- #uri? ⇒ Boolean
- #url? ⇒ Boolean
Constructor Details
#initialize(keyword, uri = nil, url = nil, options = {}) ⇒ Namespace
Returns a new instance of Namespace.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 17 def initialize(keyword, uri = nil, url = nil, = {}) raise(ArgumentError, 'keyword is nil') unless keyword @keyword = keyword @uri = uri @url = url # 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
#keyword ⇒ Object
Returns the value of attribute keyword.
11 12 13 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 11 def keyword @keyword end |
#uri ⇒ Object
Returns the value of attribute uri.
12 13 14 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 12 def uri @uri end |
#uri_reader ⇒ Object (readonly)
Returns the value of attribute uri_reader.
14 15 16 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 14 def uri_reader @uri_reader end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 13 def url @url end |
#url_reader ⇒ Object (readonly)
Returns the value of attribute url_reader.
15 16 17 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 15 def url_reader @url_reader end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
122 123 124 125 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 122 def ==(other) return false if other.nil? @keyword == other.keyword && @uri == other.uri && @url == other.url end |
#[](value) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 82 def [](value) resolved_value = if uri? && @uri_reader @uri_reader.retrieve_value_from_resource(@uri, value) elsif url? && @url_reader @url_reader.retrieve_value_from_resource(@url, value) else nil end if resolved_value value = resolved_value.first Parameter.new(self, value.name, value.encodings) else Parameter.new(self, value, nil) end end |
#domain ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 59 def domain case when uri? @uri when url? @url else nil end end |
#domain_equal?(other) ⇒ Boolean
128 129 130 131 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 128 def domain_equal?(other) return false if other.nil? @uri == other.uri && @url == other.url end |
#each ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 100 def each if block_given? values = if uri? @uri_reader.retrieve_values_from_resource(@uri) elsif url? @url_reader.retrieve_values_from_resource(@url) else [] end values.each do |value| yield Parameter.new(self, value.name, value.encodings) end else to_enum(:each) end end |
#hash ⇒ Object
118 119 120 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 118 def hash [@keyword, @uri, @url].hash end |
#include?(value) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 70 def include?(value) resolved_value = if uri? && @uri_reader @uri_reader.retrieve_value_from_resource(@uri, value) elsif url? && @url_reader @url_reader.retrieve_value_from_resource(@url, value) else nil end !resolved_value.nil? end |
#initialize_copy(original) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 32 def initialize_copy(original) @keyword = original.keyword @uri = original.uri @uri_reader = original.uri_reader @url = original.url @url_reader = original.url_reader end |
#to_s ⇒ Object
133 134 135 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 133 def to_s @keyword.to_s end |
#type ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 48 def type case when uri? :uri when url? :url else nil end end |
#uri? ⇒ Boolean
40 41 42 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 40 def uri? !@uri.nil? end |
#url? ⇒ Boolean
44 45 46 |
# File 'lib/bel_parser/expression/model/namespace.rb', line 44 def url? !@url.nil? end |