Class: MdTransformer::Markdown::Section
- Inherits:
-
Object
- Object
- MdTransformer::Markdown::Section
- Defined in:
- lib/md_transformer/markdown/section.rb
Overview
Class representing a section of a markdown file (header with content)
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
The section’s content.
-
#header_location ⇒ Range
readonly
The section header’s location in the original content.
-
#level ⇒ Integer
readonly
The precedence level of the section.
-
#title ⇒ String
readonly
The title of the section.
Class Method Summary collapse
-
.generate_sections(content) ⇒ Array
Generates an array of Section objects from string Markdown content.
Instance Method Summary collapse
-
#initialize(title, options = {}) ⇒ MdTransformer::Markdown::Section
constructor
Creates the Section object.
Constructor Details
#initialize(title, options = {}) ⇒ MdTransformer::Markdown::Section
Creates the Section object
24 25 26 27 28 29 |
# File 'lib/md_transformer/markdown/section.rb', line 24 def initialize(title, = {}) @title = title @level = [:level] || 0 @header_location = [:header_location].nil? ? 0..0 : [:header_location] @content = [:content] || '' end |
Instance Attribute Details
#content ⇒ String (readonly)
Returns the section’s content.
15 16 17 |
# File 'lib/md_transformer/markdown/section.rb', line 15 def content @content end |
#header_location ⇒ Range (readonly)
Returns the section header’s location in the original content.
12 13 14 |
# File 'lib/md_transformer/markdown/section.rb', line 12 def header_location @header_location end |
#level ⇒ Integer (readonly)
Returns the precedence level of the section.
9 10 11 |
# File 'lib/md_transformer/markdown/section.rb', line 9 def level @level end |
#title ⇒ String (readonly)
Returns the title of the section.
6 7 8 |
# File 'lib/md_transformer/markdown/section.rb', line 6 def title @title end |
Class Method Details
.generate_sections(content) ⇒ Array
Generates an array of Section objects from string Markdown content
34 35 36 37 38 39 40 41 |
# File 'lib/md_transformer/markdown/section.rb', line 34 def self.generate_sections(content) headers = header_locations(content) headers.each_with_index do |h, i| content_end = content.length headers[i] = { header: h, content: ((h.end + 1)..(content_end - 1)) } end headers.map! { |h| create_section_from_header(h, content) } end |