Class: Nasl::Integer

Inherits:
Node
  • Object
show all
Includes:
Comparable
Defined in:
lib/nasl/parser/integer.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#ctx, #tokens

Instance Method Summary collapse

Methods inherited from Node

#context, #region

Constructor Details

#initialize(tree, *tokens) ⇒ Integer

Returns a new instance of Integer.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nasl/parser/integer.rb', line 34

def initialize(tree, *tokens)
  super

  @base = case @tokens.first.type
          when :INT_DEC
            10
          when :INT_HEX
            16
          when :INT_OCT
            8
          when :FALSE
            10
          when :TRUE
            10
          end

  @value = case @tokens.first.type
           when :FALSE
             0
           when :TRUE
             1
           else
             @tokens.first.body.to_i(@base)
           end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



32
33
34
# File 'lib/nasl/parser/integer.rb', line 32

def base
  @base
end

#valueObject (readonly)

Returns the value of attribute value.



32
33
34
# File 'lib/nasl/parser/integer.rb', line 32

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



60
61
62
# File 'lib/nasl/parser/integer.rb', line 60

def <=>(other)
  self.value <=> other.value
end

#to_xml(xml) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/nasl/parser/integer.rb', line 64

def to_xml(xml)
  case @tokens.first.type
  when :FALSE
    xml.false
  when :TRUE
    xml.true
  else
    xml.integer(:value=>@value)
  end
end