Class: MdBlockConverter::Block
- Inherits:
-
Object
- Object
- MdBlockConverter::Block
- Defined in:
- lib/md_block_converter/block.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #convert! ⇒ Object
-
#initialize(lines, indent, lang) ⇒ Block
constructor
A new instance of Block.
- #to_s ⇒ Object
Constructor Details
#initialize(lines, indent, lang) ⇒ Block
Returns a new instance of Block.
7 8 9 10 11 |
# File 'lib/md_block_converter/block.rb', line 7 def initialize(lines, indent, lang) @lines = lines.map(&:lstrip) @indent = indent @lang = lang end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
5 6 7 |
# File 'lib/md_block_converter/block.rb', line 5 def indent @indent end |
#lang ⇒ Object
Returns the value of attribute lang.
5 6 7 |
# File 'lib/md_block_converter/block.rb', line 5 def lang @lang end |
#lines ⇒ Object
Returns the value of attribute lines.
5 6 7 |
# File 'lib/md_block_converter/block.rb', line 5 def lines @lines end |
Instance Method Details
#convert! ⇒ Object
13 14 15 16 17 18 |
# File 'lib/md_block_converter/block.rb', line 13 def convert! html = Nokogiri::HTML.fragment(@lines.join("\n")) text = html.text @lines = text.lines.map(&:chomp) self end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/md_block_converter/block.rb', line 20 def to_s ["```#{@lang}", *@lines, "```"].map { |line| "#{' ' * @indent}#{line}" }.join("\n") end |