Class: BEL::Model::Parameter

Inherits:
Object
  • Object
show all
Includes:
ParameterValidation, Quoting, Comparable
Defined in:
lib/bel/evidence_model/bel_parameter.rb,
lib/bel/extensions/rdf/rdf.rb

Constant Summary

Constants included from Quoting

Quoting::KeywordMatcher, Quoting::NonWordMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParameterValidation

#valid?

Methods included from Quoting

#always_quote, #ensure_quotes, #quotes_required?, #remove_quotes

Constructor Details

#initialize(ns, value, enc = nil) ⇒ Parameter

Returns a new instance of Parameter.



19
20
21
22
23
# File 'lib/bel/evidence_model/bel_parameter.rb', line 19

def initialize(ns, value, enc=nil)
  @ns = ns
  @value = value
  @enc = enc || ''
end

Instance Attribute Details

#encObject

Returns the value of attribute enc.



17
18
19
# File 'lib/bel/evidence_model/bel_parameter.rb', line 17

def enc
  @enc
end

#nsObject

Returns the value of attribute ns.



17
18
19
# File 'lib/bel/evidence_model/bel_parameter.rb', line 17

def ns
  @ns
end

#valueObject

Returns the value of attribute value.



17
18
19
# File 'lib/bel/evidence_model/bel_parameter.rb', line 17

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/bel/evidence_model/bel_parameter.rb', line 25

def <=>(other)
  ns_compare = @ns <=> other.ns
  if ns_compare == 0
    @value <=> other.value
  else
    ns_compare
  end
end

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



38
39
40
41
# File 'lib/bel/evidence_model/bel_parameter.rb', line 38

def ==(other)
  return false if other == nil
  @ns == other.ns && @value == other.value
end

#hashObject



34
35
36
# File 'lib/bel/evidence_model/bel_parameter.rb', line 34

def hash
  [@ns, @value].hash
end

#to_belObject Also known as: to_s



44
45
46
47
48
49
50
51
52
# File 'lib/bel/evidence_model/bel_parameter.rb', line 44

def to_bel
  if @ns
    prefix = @ns.respond_to?(:prefix) ? @ns.prefix : @ns[:prefix]
    prefix = prefix ? (prefix.to_s + ':') : ''
  else
    prefix = ''
  end
  %Q{#{prefix}#{ensure_quotes(@value)}}
end

#to_rdfObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bel/extensions/rdf/rdf.rb', line 31

def to_rdf
  uri = to_uri
  encodings = ['A'].concat(@enc.to_s.each_char.to_a).uniq
  if block_given?
    encodings.map { |enc| concept_statement(enc, uri) }.each do |stmt|
      yield stmt
    end
  else
    encodings.map { |enc| concept_statement(enc, uri)}
  end
end

#to_uriObject



27
28
29
# File 'lib/bel/extensions/rdf/rdf.rb', line 27

def to_uri
  @ns.to_rdf_vocabulary[URI::encode(@value)]
end