Class: Danger::Toc::MarkdownFile
- Inherits:
-
Object
- Object
- Danger::Toc::MarkdownFile
- Defined in:
- lib/toc/markdown_file.rb
Instance Attribute Summary collapse
-
#exists ⇒ Object
readonly
Returns the value of attribute exists.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#toc ⇒ Object
readonly
Returns the value of attribute toc.
Instance Method Summary collapse
- #bad? ⇒ Boolean
- #exists? ⇒ Boolean
- #good? ⇒ Boolean
- #has_toc? ⇒ Boolean
-
#initialize(filename = 'README.md') ⇒ MarkdownFile
constructor
A new instance of MarkdownFile.
- #toc_from_headers ⇒ Object
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
#exists ⇒ Object (readonly)
Returns the value of attribute exists.
10 11 12 |
# File 'lib/toc/markdown_file.rb', line 10 def exists @exists end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/toc/markdown_file.rb', line 9 def filename @filename end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/toc/markdown_file.rb', line 12 def headers @headers end |
#toc ⇒ Object (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
28 29 30 |
# File 'lib/toc/markdown_file.rb', line 28 def bad? !good? end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/toc/markdown_file.rb', line 24 def exists? !!@exists end |
#good? ⇒ Boolean
32 33 34 |
# File 'lib/toc/markdown_file.rb', line 32 def good? !!@good end |
#has_toc? ⇒ Boolean
36 37 38 |
# File 'lib/toc/markdown_file.rb', line 36 def has_toc? !!@has_toc end |
#toc_from_headers ⇒ Object
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 |