class CodeBlock::Line

A CodeBlock::Line represents a single line in the block of code. Generally you will not need to instantiate a CodeBlock::Line object yourself.

Attributes

atts[R]

Returns a hash of the name=value pairs set in the line's meta section.

number[RW]

Returns the line's number in the code block.

Public Class Methods

new(code, raw) click to toggle source

Accepts a CodeBlock object and the raw string from the code.

# File lib/codeblock.rb, line 253
def initialize(code, raw)
        @code = code
        @raw = raw
        @number = nil
        @display = @raw
        
        # unless keep meta, else strip ## and everything after
        if @code.keep_meta
                @display = @raw
        else
                @display = @raw.sub(/\s*\#\#.*/mu, '')
        end
        
        # remove trailing spaces
        @display = @display.rstrip
        
        # attributes
        if @raw.match(/\#\#/mu)
                raw_atts = @raw.sub(/\A.*\#\#\s*/mu, '')
                raw_atts = raw_atts.rstrip
                
                # if raw atts are a single string without =, use that as the name
                if raw_atts.match(/\A\S+\z/mu) and (not raw_atts.match(/\=/mu))
                        @atts = {'name'=>raw_atts}
                else
                        @atts = AttParser.parse(raw_atts, 'infer'=>true)
                end
        else
                @atts = {}
        end
end

Public Instance Methods

has_content?() click to toggle source

Returns true if the line has any non-space characters.

# File lib/codeblock.rb, line 355
def has_content?
        return @display.match(/\S/mu)
end
name() click to toggle source

Returns the value of 'name' in the line's attributes. Returns nil if no name was set.

# File lib/codeblock.rb, line 310
def name
        return @atts['name']
end
no_content?() click to toggle source

Returns false if the line has any non-space characters.

# File lib/codeblock.rb, line 360
def no_content?
        return !has_content?
end
notes() click to toggle source

Returns the value of 'notes' in the line's attributes. Returns nil if no notes were set.

# File lib/codeblock.rb, line 322
def notes
        return @atts['notes']
end
skip() click to toggle source

Returns the value of 'skip' in the line's attributes. Returns nil if no skip was set.

# File lib/codeblock.rb, line 316
def skip
        return @atts['skip']
end
to_s() click to toggle source

Returns the line as it should be displayed, taking into account tabs, indentation, line number, etc. If the line is to be skipped then nil is returned.

# File lib/codeblock.rb, line 338
def to_s
        if @atts['skip'] and (not @code.skip_skips)
                return nil
        else
                return @display
        end
end