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.



212
213
214
215
# File 'lib/bel/language.rb', line 212

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

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



211
212
213
# File 'lib/bel/language.rb', line 211

def encoding
  @encoding
end

#varObject (readonly)

Returns the value of attribute var.



211
212
213
# File 'lib/bel/language.rb', line 211

def var
  @var
end

Instance Method Details

#<=>(other) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/bel/language.rb', line 217

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



236
237
238
# File 'lib/bel/language.rb', line 236

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