Class: Glaemscribe::API::Glaeml::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/api/glaeml.rb

Defined Under Namespace

Classes: Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, type, name) ⇒ Node

Returns a new instance of Node.



62
63
64
65
66
67
68
# File 'lib/api/glaeml.rb', line 62

def initialize(line, type, name)
  @line         = line
  @type         = type
  @name         = name
  @args         = []
  @children     = []
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



104
105
106
# File 'lib/api/glaeml.rb', line 104

def args
  @args
end

#childrenObject (readonly)

Returns the value of attribute children.



105
106
107
# File 'lib/api/glaeml.rb', line 105

def children
  @children
end

#lineObject

Returns the value of attribute line.



99
100
101
# File 'lib/api/glaeml.rb', line 99

def line
  @line
end

#nameObject (readonly)

Returns the value of attribute name.



102
103
104
# File 'lib/api/glaeml.rb', line 102

def name
  @name
end

#parent_nodeObject

Returns the value of attribute parent_node.



107
108
109
# File 'lib/api/glaeml.rb', line 107

def parent_node
  @parent_node
end

#typeObject (readonly)

Returns the value of attribute type.



101
102
103
# File 'lib/api/glaeml.rb', line 101

def type
  @type
end

Instance Method Details

#element?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/api/glaeml.rb', line 58

def element?
  @type == Type::ElementInline || @type == Type::ElementBlock
end

#gpath(path) ⇒ Object



92
93
94
95
96
97
# File 'lib/api/glaeml.rb', line 92

def gpath(path)
  apath = path.split(".")
  found = []
  pathfind_crawl(apath, found)
  found
end

#initialize_copy(other) ⇒ Object

Make our object clonable



71
72
73
74
75
# File 'lib/api/glaeml.rb', line 71

def initialize_copy(other)
  super
  @args = other.args.clone
  @children = other.children.map{|c| c.clone}
end

#pathfind_crawl(apath, found) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/api/glaeml.rb', line 77

def pathfind_crawl(apath, found)

  children.each{ |c|
    if(c.name == apath[0])
      if apath.count == 1
        found << c
      else
        bpath = apath.dup
        bpath.shift
        c.pathfind_crawl(bpath, found)
      end
    end
  }
end

#text?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/api/glaeml.rb', line 54

def text?
  @type == Type::Text
end