Class: RShade::Formatter::String

Inherits:
Object
  • Object
show all
Defined in:
lib/rshade/formatter/string.rb

Direct Known Subclasses

Stdout

Constant Summary collapse

ROOT_SEP =
"---\n"

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ String

Returns a new instance of String.



6
7
# File 'lib/rshade/formatter/string.rb', line 6

def initialize(opts= {})
end

Instance Method Details

#call(event_store) ⇒ Object

Parameters:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rshade/formatter/string.rb', line 10

def call(event_store)
  buffer = StringIO.new
  event_store.each_with_index do |node, idx|
    depth = node.level
    event = node.value
    if depth == 1
      buffer << ROOT_SEP
      next
    end
    next unless event
    buffer.write line(idx, event, node.vlevel)
  end
  buffer.string
end

#line(line_idx, value, depth) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rshade/formatter/string.rb', line 25

def line(line_idx, value, depth)
  vars = value.vars
  returned = ColorizedString["=> |#{value.return_value}|"].colorize(:magenta)

  class_method = ColorizedString["#{value.klass}##{value.method_name}"].colorize(:green)
  full_path = ColorizedString["#{value.path}:#{value.lineno}"].colorize(:blue)
  line_idx = ColorizedString["[#{line_idx}] "].colorize(:red)
  "#{'  ' * depth}#{line_idx}#{class_method}(#{vars}) #{returned} -> #{full_path}\n"
end