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.



75
76
77
78
# File 'lib/bel/language.rb', line 75

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

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



74
75
76
# File 'lib/bel/language.rb', line 74

def encoding
  @encoding
end

#varObject (readonly)

Returns the value of attribute var.



74
75
76
# File 'lib/bel/language.rb', line 74

def var
  @var
end

Instance Method Details

#<=>(other) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bel/language.rb', line 80

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



99
100
101
# File 'lib/bel/language.rb', line 99

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