Class: BELParser::Expression::Model::Parameter

Inherits:
Object
  • Object
show all
Includes:
Quoting, Comparable
Defined in:
lib/bel_parser/expression/model/parameter.rb

Constant Summary

Constants included from Quoting

Quoting::KeywordMatcher, Quoting::Keywords, Quoting::LenientQuotedMatcher, Quoting::NonWordMatcher, Quoting::QuoteNotEscapedMatcher, Quoting::StrictQuotedMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Quoting

#identifier_value?, #quote, #quote_if_needed, #quoted?, #string_value?, #unquote, #unquoted?

Constructor Details

#initialize(namespace, value, encoding = nil) ⇒ Parameter

Returns a new instance of Parameter.



14
15
16
17
18
19
20
# File 'lib/bel_parser/expression/model/parameter.rb', line 14

def initialize(namespace, value, encoding = nil)
  assert_namespace_type(namespace)
  assert_value_type(value)
  @namespace = namespace
  @value     = value
  @encoding  = encoding
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#namespaceObject

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/bel_parser/expression/model/parameter.rb', line 41

def <=>(other)
  namespace_compare = @namespace <=> other.namespace
  if namespace_compare == 0
    @value <=> other.value
  else
    namespace_compare
  end
end

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



54
55
56
57
# File 'lib/bel_parser/expression/model/parameter.rb', line 54

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

#hashObject



50
51
52
# File 'lib/bel_parser/expression/model/parameter.rb', line 50

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

#invalid?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bel_parser/expression/model/parameter.rb', line 37

def invalid?
  !valid?
end

#to_s(_ = :short) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/bel_parser/expression/model/parameter.rb', line 60

def to_s(_ = :short)
  if @namespace
    prefix = "#{@namespace.keyword}:"
  else
    prefix = ''
  end
  %Q{#{prefix}#{quote_if_needed(@value)}}
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/bel_parser/expression/model/parameter.rb', line 32

def valid?
  return true if @namespace.nil?
  @namespace.include?(@value)
end