class Columnist::NestedFormatter

Constants

VALID_OPTIONS

Attributes

bold[RW]
color[RW]
complete_string[RW]
indent_size[RW]
message_string[RW]

Public Instance Methods

format(options, block) click to toggle source
# File lib/columnist/formatter/nested.rb, line 12
def format(options, block)
    self.validate_options(options, *VALID_OPTIONS)

    indent_level :incr

    padding = ' ' * @indent_level * (options[:indent_size] || self.indent_size)

    message_str  = padding + (options[:message] || self.message_string)
    complete_str = options[:complete] || self.complete_string

    if options[:type] == 'inline'
        colorize("#{message_str}...", true, options)
    else
        colorize(message_str, false, options)
        complete_str = padding + complete_str
    end

    block.call

    colorize(complete_str, false, options)

    indent_level :decr
end

Private Instance Methods

colorize(str, inline, options) click to toggle source
# File lib/columnist/formatter/nested.rb, line 50
def colorize(str, inline, options)
    str = str.send(options[:color]) if options[:color]
    str = str.bold if options[:bold]

    if inline
        print str
    else
        puts str
    end
end
indent_level(value) click to toggle source
# File lib/columnist/formatter/nested.rb, line 61
def indent_level(value)
    case value
        when :incr
            @indent_level = (@indent_level) ? @indent_level + 1 : 0
        when :decr
            @indent_level -= 1
    end
end