Class: Binenc::BinTag

Inherits:
Object
  • Object
show all
Includes:
TR::CondUtils
Defined in:
lib/binenc/bin_tag/bin_tag.rb

Overview

binary tagging constant helper

Instance Method Summary collapse

Constructor Details

#initializeBinTag

include Singleton



11
12
13
14
# File 'lib/binenc/bin_tag/bin_tag.rb', line 11

def initialize
  @constRaiseIfDup = false
  @constant = {  }
end

Instance Method Details

#constant_value(key) ⇒ Object



48
49
50
# File 'lib/binenc/bin_tag/bin_tag.rb', line 48

def constant_value(key)
  @constant[key]
end

#define_constant(key, val, parent = nil, &block) ⇒ Object

DSL part



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/binenc/bin_tag/bin_tag.rb', line 23

def define_constant(key, val, parent = nil, &block)
  if @constant.keys.include?(key) 
    if @constRaiseIfDup
      raise BinTagConstantKeyAlreadyExist, "Constant key '#{key}' already exist"
    else
      logger.warn "Overwriting existing key '#{key}'..."
    end
  end

  if val.is_a?(String) and val =~ /#/
    val = val.gsub("#",@parent).strip
  end

  @constant[key] = val

  oldParent = @parent 

  @parent = val
  if block
    instance_eval(&block)
  end
  @parent = oldParent

end

#is_raise_on_constant_key_duplicate?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/binenc/bin_tag/bin_tag.rb', line 67

def is_raise_on_constant_key_duplicate?
  @constRaiseIfDup
end

#load(&block) ⇒ Object



16
17
18
# File 'lib/binenc/bin_tag/bin_tag.rb', line 16

def load(&block)
  instance_eval(&block)
end

#raise_on_constant_key_duplicate=(val) ⇒ Object



64
65
66
# File 'lib/binenc/bin_tag/bin_tag.rb', line 64

def raise_on_constant_key_duplicate=(val)
  @constRaiseIfDup = val
end

#value_constant(val) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/binenc/bin_tag/bin_tag.rb', line 52

def value_constant(val)
  #if TR::RTUtils.on_java?
    if val.is_a?(Integer)
      @constant.invert[val.to_s.to_i]
    else
      @constant.invert[val]
    end
  #else
  #  @constant.invert[val]
  #end
end