Class: DocGen::Context

Inherits:
Struct
  • Object
show all
Defined in:
lib/doc_gen/parser.rb

Overview

A context represents a ‘describe` block. It holds child contexts and specs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def children
  @children
end

#docstringObject

Returns the value of attribute docstring

Returns:

  • (Object)

    the current value of docstring



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def docstring
  @docstring
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def file
  @file
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def line
  @line
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def name
  @name
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



15
16
17
# File 'lib/doc_gen/parser.rb', line 15

def parent
  @parent
end

Instance Method Details

#full_nameObject

Full display name, dropping the root component when nested. Examples:

root 'Site::Tlc::Io'       => 'Site::Tlc::Io'
child 'IO' of above         => 'IO'
grandchild 'Input' of above => 'IO Input'


31
32
33
34
35
36
37
38
39
40
# File 'lib/doc_gen/parser.rb', line 31

def full_name
  parts = [name]
  ctx = parent
  while ctx.is_a?(Context)
    parts.unshift(ctx.name)
    ctx = ctx.parent
  end
  parts.shift if parts.size > 1
  parts.join(' ')
end

#output_pathObject

Hierarchical output path relative to the output directory root. Examples:

root 'Site::Tlc::Io'              => 'site_tlc_io.md'
child 'IO'                         => 'site_tlc_io/io.md'
grandchild 'Input'                 => 'site_tlc_io/io/input.md'


47
48
49
50
51
52
53
54
55
# File 'lib/doc_gen/parser.rb', line 47

def output_path
  parts = []
  ctx = self
  while ctx.is_a?(Context)
    parts.unshift(DocGen.slugify(ctx.name))
    ctx = ctx.parent
  end
  "#{parts.join('/')}.md"
end

#specsObject

Direct child specs (it/specify blocks).



17
18
19
# File 'lib/doc_gen/parser.rb', line 17

def specs
  children.grep(Spec)
end

#subcontextsObject

Direct child contexts (nested describe blocks).



22
23
24
# File 'lib/doc_gen/parser.rb', line 22

def subcontexts
  children.grep(Context)
end