Class: BELParser::Expression::Model::Namespace

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(keyword, uri = nil, url = nil, options = {}) ⇒ Namespace

Returns a new instance of Namespace.

Raises:

  • (ArgumentError)


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, options = {})
  raise(ArgumentError, 'keyword is nil') unless keyword
  @keyword = keyword
  @uri     = uri
  @url     = url

  # configure reader for URIs (RDF).
  @uri_reader = options.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 = options.fetch(:url_reader, BELParser::Resource.default_url_reader)
  BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader')
end

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



11
12
13
# File 'lib/bel_parser/expression/model/namespace.rb', line 11

def keyword
  @keyword
end

#uriObject

Returns the value of attribute uri.



12
13
14
# File 'lib/bel_parser/expression/model/namespace.rb', line 12

def uri
  @uri
end

#uri_readerObject (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

#urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/bel_parser/expression/model/namespace.rb', line 13

def url
  @url
end

#url_readerObject (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

#domainObject



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

Returns:

  • (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

#eachObject



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

#hashObject



118
119
120
# File 'lib/bel_parser/expression/model/namespace.rb', line 118

def hash
  [@keyword, @uri, @url].hash
end

#include?(value) ⇒ Boolean

Returns:

  • (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_sObject



133
134
135
# File 'lib/bel_parser/expression/model/namespace.rb', line 133

def to_s
  @keyword.to_s
end

#typeObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/bel_parser/expression/model/namespace.rb', line 40

def uri?
  !@uri.nil?
end

#url?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bel_parser/expression/model/namespace.rb', line 44

def url?
  !@url.nil?
end