Class: Snuffle::Node

Inherits:
Object
  • Object
show all
Includes:
Ephemeral::Base, PoroPlus
Defined in:
lib/snuffle/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Node

Returns a new instance of Node.



24
25
26
27
# File 'lib/snuffle/node.rb', line 24

def initialize(*args, &block)
  @id = SecureRandom.uuid
  super
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def args
  @args
end

#child_idsObject

Returns the value of attribute child_ids.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def child_ids
  @child_ids
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def id
  @id
end

#line_numbersObject

Returns the value of attribute line_numbers.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def line_numbers
  @line_numbers
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def name
  @name
end

#parent_idObject

Returns the value of attribute parent_id.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def parent_id
  @parent_id
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/snuffle/node.rb', line 8

def type
  @type
end

Class Method Details

.nilObject



16
17
18
# File 'lib/snuffle/node.rb', line 16

def self.nil
  new(type: :nil)
end

.not_a(type) ⇒ Object



20
21
22
# File 'lib/snuffle/node.rb', line 20

def self.not_a(type)
  select{|node| node.type != type}
end

Instance Method Details

#childrenObject



37
38
39
# File 'lib/snuffle/node.rb', line 37

def children
  Snuffle::Node.where(parent_id: self.id)
end

#inspectObject



49
50
51
52
53
54
55
56
# File 'lib/snuffle/node.rb', line 49

def inspect
  {
    id: self.id,
    type: self.type,
    parent_id: self.parent_id,
    child_ids: self.child_ids
  }.to_s
end

#is_methodObject



41
42
43
# File 'lib/snuffle/node.rb', line 41

def is_method
  self.type == :def || self.type == :defs
end

#is_sendObject



45
46
47
# File 'lib/snuffle/node.rb', line 45

def is_send
  self.type == :send
end

#parentObject



29
30
31
# File 'lib/snuffle/node.rb', line 29

def parent
  Snuffle::Node.where(id: self.parent_id).first
end

#siblingsObject



33
34
35
# File 'lib/snuffle/node.rb', line 33

def siblings
  @siblings ||= Snuffle::Node.by_type(self.type).to_a - [self]
end