Class: Danger::Toc::MarkdownFile

Inherits:
Object
  • Object
show all
Defined in:
lib/toc/markdown_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = 'README.md') ⇒ MarkdownFile

Returns a new instance of MarkdownFile.



14
15
16
17
18
19
20
21
22
# File 'lib/toc/markdown_file.rb', line 14

def initialize(filename = 'README.md')
  @filename = filename
  @exists = File.exist?(filename)
  if @exists
    parse!
    reduce!
    validate!
  end
end

Instance Attribute Details

#existsObject (readonly)

Returns the value of attribute exists.



10
11
12
# File 'lib/toc/markdown_file.rb', line 10

def exists
  @exists
end

#filenameObject (readonly)

Returns the value of attribute filename.



9
10
11
# File 'lib/toc/markdown_file.rb', line 9

def filename
  @filename
end

#headersObject (readonly)

Returns the value of attribute headers.



12
13
14
# File 'lib/toc/markdown_file.rb', line 12

def headers
  @headers
end

#tocObject (readonly)

Returns the value of attribute toc.



11
12
13
# File 'lib/toc/markdown_file.rb', line 11

def toc
  @toc
end

Instance Method Details

#bad?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/toc/markdown_file.rb', line 28

def bad?
  !good?
end

#exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/toc/markdown_file.rb', line 24

def exists?
  !!@exists
end

#good?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/toc/markdown_file.rb', line 32

def good?
  !!@good
end

#has_toc?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/toc/markdown_file.rb', line 36

def has_toc?
  !!@has_toc
end

#toc_from_headersObject



40
41
42
43
44
45
46
47
48
# File 'lib/toc/markdown_file.rb', line 40

def toc_from_headers
  headers.map do |header|
    [
      ' ' * header[:depth] * 2,
      "- [#{header[:text]}]",
      "(##{header[:id]})"
    ].compact.join
  end
end