class CodeBlockDeterminator

Copyright 2014 Huub de Beer

This file is part of Foobar.

Foucault is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Foucault is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Foucault. If not, see <www.gnu.org/licenses/>.

Constants

FENCE

Public Class Methods

new() click to toggle source
# File lib/foucault/code_block_determinator.rb, line 19
def initialize()
    to_start_state
end

Public Instance Methods

collect_line?(line) click to toggle source
# File lib/foucault/code_block_determinator.rb, line 23
def collect_line?(line) 

    case @state

    when :fenced_block
        if is_fence?(line) and fence_size(line) >= @size and fence_type(line) == @type then
             # recognized the end of this code block
             to_start_state 
        else
            # We're still in a code block: collect this line
            return true
        end            

    when :start
        if is_fence?(line)
            # Start of a new code block
            @state = :fenced_block
            @type = fence_type line
            @size = fence_size line
        end
    end
    
    # not in a code block: don't collect this line
    return false
end

Private Instance Methods

fence_size(line) click to toggle source
# File lib/foucault/code_block_determinator.rb, line 63
def fence_size(line)
    FENCE.match(line)[:fence].size
end
fence_type(line) click to toggle source
# File lib/foucault/code_block_determinator.rb, line 67
def fence_type(line)
    FENCE.match(line)[:type]
end
is_fence?(line) click to toggle source
# File lib/foucault/code_block_determinator.rb, line 59
def is_fence?(line)
    FENCE.match line
end
to_start_state() click to toggle source
# File lib/foucault/code_block_determinator.rb, line 51
def to_start_state()
    @state = :start
    @size = 0
    @type = :none
end