Module: RgGen::Core::Utility::CodeUtility
- Included in:
- SourceFile, StructureDefinition
- Defined in:
- lib/rggen/core/utility/code_utility.rb,
lib/rggen/core/utility/code_utility/line.rb,
lib/rggen/core/utility/code_utility/code_block.rb,
lib/rggen/core/utility/code_utility/source_file.rb,
lib/rggen/core/utility/code_utility/structure_definition.rb
Defined Under Namespace
Classes: CodeBlock, Line, MacroDefinition, SourceFile, StructureDefinition
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.array_name(name, size) ⇒ Object
41
42
43
|
# File 'lib/rggen/core/utility/code_utility.rb', line 41
def array_name(name, size)
[name, *size&.map { |s| "[#{s}]" }].join
end
|
.code_block(indent = 0, &body) ⇒ Object
45
46
47
|
# File 'lib/rggen/core/utility/code_utility.rb', line 45
def code_block(indent = 0, &body)
CodeBlock.new(indent, &body)
end
|
25
26
27
|
# File 'lib/rggen/core/utility/code_utility.rb', line 25
def colon
':'
end
|
21
22
23
|
# File 'lib/rggen/core/utility/code_utility.rb', line 21
def comma
','
end
|
.indent(code, indent_size) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/rggen/core/utility/code_utility.rb', line 49
def indent(code, indent_size)
code << nl unless code.last_line_empty?
code.indent += indent_size
block_given? && yield(code)
code << nl unless code.last_line_empty?
code.indent -= indent_size
end
|
.loop_index(level = 1) ⇒ Object
63
64
65
66
|
# File 'lib/rggen/core/utility/code_utility.rb', line 63
def loop_index(level = 1)
return '' unless level.positive?
(1...level).inject(+'i') { |index, _| index.next! }
end
|
13
14
15
|
# File 'lib/rggen/core/utility/code_utility.rb', line 13
def newline
"\n"
end
|
17
18
19
|
# File 'lib/rggen/core/utility/code_utility.rb', line 17
def nl
newline
end
|
.semicolon ⇒ Object
29
30
31
|
# File 'lib/rggen/core/utility/code_utility.rb', line 29
def semicolon
';'
end
|
.space(size = 1) ⇒ Object
33
34
35
|
# File 'lib/rggen/core/utility/code_utility.rb', line 33
def space(size = 1)
' ' * size
end
|
.string(expression) ⇒ Object
37
38
39
|
# File 'lib/rggen/core/utility/code_utility.rb', line 37
def string(expression)
"\"#{expression}\""
end
|
.wrap(code, head, tail) ⇒ Object
57
58
59
60
61
|
# File 'lib/rggen/core/utility/code_utility.rb', line 57
def wrap(code, head, tail)
code << head
block_given? && yield(code)
code << tail
end
|
Instance Method Details
#create_blank_code ⇒ Object
7
8
9
|
# File 'lib/rggen/core/utility/code_utility.rb', line 7
def create_blank_code
code_block
end
|