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.



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

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

Instance Attribute Details

#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



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

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

.not_a(type) ⇒ Object



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

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

Instance Method Details

#childrenObject



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

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

#inspectObject



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

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

#is_methodObject



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

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

#is_sendObject



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

def is_send
  self.type == :send
end

#parentObject



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

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

#siblingsObject



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

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