Sha256: 23eca4f38052517754d42f05b3f2f995d8f293c30716ff7cdc0df82d1b6c70bf
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
module Brief class Line attr_reader :_content, :number, :code attr_accessor :raw HeadingRegex = /^#+\s*/ CodeBlockRegex = /^\s*```/ def initialize(content, number, code=false) @_content = content @number = number + 1 @code = code end def to_s content end def type case when code? "content" when _content.match(HeadingRegex) "heading" when _content.match(CodeBlockRegex) "code_block_marker" else "content" end end def content _content.gsub(HeadingRegex, '') end def raw @raw || _content end def heading? !code? && type == "heading" end def level _content.match(HeadingRegex).to_s.count('#') end def sort_index [level, number] end def line_number number end def content? type == "content" || type == "code_block_marker" end def code? !!@code end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
brief-0.0.5 | lib/brief/line.rb |
brief-0.0.4 | lib/brief/line.rb |
brief-0.0.3 | lib/brief/line.rb |
brief-0.0.2 | lib/brief/line.rb |