Class: BEL::Namespace::NamespaceDefinition

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

Overview

OpenClass to contribute RDF functionality to BEL Model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of NamespaceDefinition.



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

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

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



239
240
241
# File 'lib/bel/namespace.rb', line 239

def prefix
  @prefix
end

#rdf_uriObject (readonly)

Returns the value of attribute rdf_uri.



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

def rdf_uri
  @rdf_uri
end

#urlObject (readonly)

Returns the value of attribute url.



240
241
242
# File 'lib/bel/namespace.rb', line 240

def url
  @url
end

Instance Method Details

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



280
281
282
283
# File 'lib/bel/namespace.rb', line 280

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

#[](value) ⇒ Object



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

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

#each(&block) ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'lib/bel/namespace.rb', line 265

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

#hashObject



276
277
278
# File 'lib/bel/namespace.rb', line 276

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

#to_belObject



291
292
293
# File 'lib/bel/namespace.rb', line 291

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

#to_rdf_vocabularyObject



20
21
22
# File 'lib/bel/extensions/rdf/rdf.rb', line 20

def to_rdf_vocabulary
  RUBYRDF::Vocabulary.new("#{@rdf_uri}/")
end

#to_sObject



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

def to_s
  @prefix.to_s
end

#to_uriObject



16
17
18
# File 'lib/bel/extensions/rdf/rdf.rb', line 16

def to_uri
  @rdf_uri
end

#valuesObject



250
251
252
253
254
255
# File 'lib/bel/namespace.rb', line 250

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