Class: XRay::JS::Element

Inherits:
Node
  • Object
show all
Defined in:
lib/js/struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, left = nil, right = nil, position = nil) ⇒ Element

Returns a new instance of Element.



10
11
12
# File 'lib/js/struct.rb', line 10

def initialize(type, left = nil, right = nil, position = nil)
  @type, @left, @right, @position = type, left, right, position
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



8
9
10
# File 'lib/js/struct.rb', line 8

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



8
9
10
# File 'lib/js/struct.rb', line 8

def right
  @right
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/js/struct.rb', line 8

def type
  @type
end

Instance Method Details

#contains?(target) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/js/struct.rb', line 24

def contains?(target)
  return true if target == @type
  left && left.respond_to?(:contains?) && left.contains?(target) or 
    right && right.respond_to?(:contains?) && right.contains?(target)
end

#positionObject



18
19
20
21
22
# File 'lib/js/struct.rb', line 18

def position
  @position ? @position : 
      left ? left.position : 
      right ? right.position : nil
end

#textObject



14
15
16
# File 'lib/js/struct.rb', line 14

def text
  "(#{type},#{left},#{right})"
end