Class: BEL::Language::E

Inherits:
Object
  • Object
show all
Defined in:
lib/bel/language.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoding, var = false) ⇒ E

Returns a new instance of E.



202
203
204
205
# File 'lib/bel/language.rb', line 202

def initialize(encoding, var=false)
  @encoding = encoding
  @var = var
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



201
202
203
# File 'lib/bel/language.rb', line 201

def encoding
  @encoding
end

#varObject (readonly)

Returns the value of attribute var.



201
202
203
# File 'lib/bel/language.rb', line 201

def var
  @var
end

Instance Method Details

#<=>(other) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/bel/language.rb', line 207

def <=>(other)
  return 1 if @var ^ other.var

  # compare for equals and wildcard case
  cmp = @encoding <=> other.encoding
  return cmp if cmp.zero? or (@encoding == :* or other.encoding == :*)

  # compare encoding for assignability; based on array index
  @encoding.to_s.each_char do |enc_char|
    enc_sym = enc_char.to_sym
    tree = PARAMETER_ENCODING[enc_sym]
    next if not tree.include?(other.encoding)

    match = -(tree.index(enc_sym) <=> tree.index(other.encoding))
    return match if match >= 0
  end
  -1
end

#to_sObject



226
227
228
# File 'lib/bel/language.rb', line 226

def to_s
  "E:#{@encoding}"
end