Module: Babeltrace2Gen::BTPrinter

Constant Summary collapse

INDENT_INCREMENT =
'  '.freeze
@@output =
''
@@indent =
0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.context(output: '', indent: 0) ⇒ Object



20
21
22
23
24
25
# File 'lib/metababel/bt2_generator_utils.rb', line 20

def self.context(output: '', indent: 0)
  @@output = output
  @@indent = indent
  yield
  @@output
end

.pr(str) ⇒ Object



7
8
9
# File 'lib/metababel/bt2_generator_utils.rb', line 7

def pr(str)
  @@output << (INDENT_INCREMENT * @@indent) << str << "\n"
end

Instance Method Details

#name_sanitizedObject

Maybe not the best place



28
29
30
31
32
# File 'lib/metababel/bt2_generator_utils.rb', line 28

def name_sanitized
  raise unless @name

  @name.gsub(/[^0-9A-Za-z-]/, '_')
end

#scopeObject



12
13
14
15
16
17
18
# File 'lib/metababel/bt2_generator_utils.rb', line 12

def scope
  pr '{'
  @@indent += 1
  yield
  @@indent -= 1
  pr '}'
end