Class: Fdlint::Parser::JS::Element

Inherits:
Node
  • Object
show all
Defined in:
lib/fdlint/parser/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.



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

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.



12
13
14
# File 'lib/fdlint/parser/js/struct.rb', line 12

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



12
13
14
# File 'lib/fdlint/parser/js/struct.rb', line 12

def right
  @right
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/fdlint/parser/js/struct.rb', line 12

def type
  @type
end

Instance Method Details

#contains?(target) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/fdlint/parser/js/struct.rb', line 28

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



22
23
24
25
26
# File 'lib/fdlint/parser/js/struct.rb', line 22

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

#textObject



18
19
20
# File 'lib/fdlint/parser/js/struct.rb', line 18

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