Class: BELParser::Expression::Model::Annotation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bel_parser/expression/model/annotation.rb

Overview

Annotation represents a catalog of biological annotation values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, type, domain, options = {}) ⇒ Annotation

Returns a new instance of Annotation.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bel_parser/expression/model/annotation.rb', line 14

def initialize(keyword, type, domain, options = {})
  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

  uri_reader = options.fetch(:uri_reader, nil)
  url_reader = options.fetch(:url_reader, nil)
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



10
11
12
# File 'lib/bel_parser/expression/model/annotation.rb', line 10

def domain
  @domain
end

#keywordObject

Returns the value of attribute keyword.



8
9
10
# File 'lib/bel_parser/expression/model/annotation.rb', line 8

def keyword
  @keyword
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/bel_parser/expression/model/annotation.rb', line 9

def type
  @type
end

#uri_readerObject

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_readerObject

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?



85
86
87
88
89
90
# File 'lib/bel_parser/expression/model/annotation.rb', line 85

def ==(other)
  return false if other.nil?
  @keyword == other.keyword &&
    @type == other.type &&
    @domain == other.domain
end

#[](value) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/bel_parser/expression/model/annotation.rb', line 53

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

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/bel_parser/expression/model/annotation.rb', line 93

def domain_equal?(other)
  return false if other.nil?
  @type == other.type && @domain == other.domain
end

#eachObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bel_parser/expression/model/annotation.rb', line 63

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

#hashObject



81
82
83
# File 'lib/bel_parser/expression/model/annotation.rb', line 81

def hash
  [@keyword, @type, @domain].hash
end

#initialize_copy(original) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bel_parser/expression/model/annotation.rb', line 27

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_sObject



98
99
100
# File 'lib/bel_parser/expression/model/annotation.rb', line 98

def to_s
  @keyword.to_s
end

#uri?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/bel_parser/expression/model/annotation.rb', line 45

def uri?
  @type == :uri
end

#url?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bel_parser/expression/model/annotation.rb', line 49

def url?
  @type == :url
end