Class: Columnist::NestedFormatter

Inherits:
Object
  • Object
show all
Includes:
OptionsValidator, Singleton
Defined in:
lib/columnist/formatter/nested.rb

Constant Summary collapse

VALID_OPTIONS =
[:message, :type, :complete, :indent_size, :color, :bold]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsValidator

#validate_options

Instance Attribute Details

#boldObject

Returns the value of attribute bold.



10
11
12
# File 'lib/columnist/formatter/nested.rb', line 10

def bold
  @bold
end

#colorObject

Returns the value of attribute color.



10
11
12
# File 'lib/columnist/formatter/nested.rb', line 10

def color
  @color
end

#complete_stringObject

Returns the value of attribute complete_string.



10
11
12
# File 'lib/columnist/formatter/nested.rb', line 10

def complete_string
  @complete_string
end

#indent_sizeObject

Returns the value of attribute indent_size.



10
11
12
# File 'lib/columnist/formatter/nested.rb', line 10

def indent_size
  @indent_size
end

#message_stringObject

Returns the value of attribute message_string.



10
11
12
# File 'lib/columnist/formatter/nested.rb', line 10

def message_string
  @message_string
end

Instance Method Details

#format(options, block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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