Class: ARST::Node::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arst/node/base.rb

Direct Known Subclasses

Class, Extend, Include, Module, Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
# File 'lib/arst/node/base.rb', line 10

def initialize(options={})
  # TODO: Validate keys
  options = default_options.merge(options)
  
  @parent, @children = options.values_at(:parent, :children)
  @children.collect! { |child_options| Node.from_options( child_options.merge(parent: self) ) }
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

Instance Method Details

#ancestorsObject



18
19
20
21
22
# File 'lib/arst/node/base.rb', line 18

def ancestors
  return [] if parent.nil?
  
  ( parent.ancestors || [] ) + [self]
end

#typeObject



24
25
26
# File 'lib/arst/node/base.rb', line 24

def type
  @type ||= ARST::Helpers.underscore(self.class.to_s.split(/::/).last).to_sym
end