Class: BEL::Namespace::NamespaceDefinition

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bel/translator/plugins/rdf/monkey_patch.rb,
lib/bel/namespace.rb

Overview

OpenClass to contribute RDF functionality to BEL Nanopub objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, url, rdf_uri = DEFAULT_URI) ⇒ NamespaceDefinition

Returns a new instance of NamespaceDefinition.



246
247
248
249
250
251
# File 'lib/bel/namespace.rb', line 246

def initialize(prefix, url, rdf_uri = DEFAULT_URI)
  @prefix = prefix
  @url = url
  @rdf_uri = rdf_uri
  @values = nil
end

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



242
243
244
# File 'lib/bel/namespace.rb', line 242

def prefix
  @prefix
end

#rdf_uriObject

Returns the value of attribute rdf_uri.



244
245
246
# File 'lib/bel/namespace.rb', line 244

def rdf_uri
  @rdf_uri
end

#urlObject

Returns the value of attribute url.



243
244
245
# File 'lib/bel/namespace.rb', line 243

def url
  @url
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



287
288
289
290
# File 'lib/bel/namespace.rb', line 287

def ==(other)
  return false if other == nil
  @prefix == other.prefix && @url == other.url
end

#[](value) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/bel/namespace.rb', line 264

def [](value)
  return nil unless value
  reload(@url) if not @values
  sym = value.to_sym
  encoding = @values[sym] || :''
  Nanopub::Parameter.new(self, sym, encoding)
end

#each(&block) ⇒ Object



272
273
274
275
276
277
278
279
280
281
# File 'lib/bel/namespace.rb', line 272

def each &block
  reload(@url) if not @values
  @values.each do |val, enc|
    if block_given?
      block.call(Nanopub::Parameter.new(self, val, enc))
    else
      yield Nanopub::Parameter.new(self, val, enc)
    end
  end
end

#hashObject



283
284
285
# File 'lib/bel/namespace.rb', line 283

def hash
  [@prefix, @url].hash
end

#to_belObject



298
299
300
# File 'lib/bel/namespace.rb', line 298

def to_bel
  %Q{DEFINE NAMESPACE #{@prefix} AS URL "#{@url}"}
end

#to_rdf_vocabularyObject



15
16
17
18
19
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 15

def to_rdf_vocabulary
  uri = @rdf_uri
  uri << '/' if uri && !uri.end_with?('/')
  ::RDF::Vocabulary.new(uri)
end

#to_sObject



294
295
296
# File 'lib/bel/namespace.rb', line 294

def to_s
  @prefix.to_s
end

#to_uriObject



11
12
13
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 11

def to_uri
  rdf_uri
end

#valuesObject



257
258
259
260
261
262
# File 'lib/bel/namespace.rb', line 257

def values
  unless @values
    reload(@url)
  end
  @values
end