4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/joe_utils/script_renderer.rb', line 4
def render_script(file_path)
lines = File.open(file_path, 'r') { |f| f.readlines }
structures, requires, , modules, klass, methods, class_name, full_class_name = [], [], [], [], '', {}, '', ''
class_began, private_began, public_began, methods_began, structure_began = false, false, true, false, false
lines.each do |line|
line.strip!
if line[0] == '#'
<< line[1..-1]
elsif line =~ /^require /
match = line.match(/\brequire ['"]/)
requires << match.post_match[0..-2]
elsif line =~ /^module /
match = line.match(/\bmodule /)
modules << match.post_match[/\b[A-Z]+(::[A-Z_]+)*\b/]
elsif line =~ /^class /
class_began = true
klass = line[/^class [A-Za-z_]+(::[A-Za-z_]+)*/][6..-1].split('::').last
elsif line =~ /^def initialize/
methods_began = true
elsif line =~ /^def /
methods[line[/^def \w+/][4..-1]] = {arguments: []}
elsif line =~ /^private /
private_began = true
elsif line =~ /^[A-Z]+\b = {/ && class_began && !methods_began
structure_began = true
structures << {name: line[/^[A-Z]+\b/] }
structures.last[:content] = {}
elsif line =~ /^[a-z_]+: ?/ && structure_began
match = line.match(/^[a-z_]+: ?/)
structures.last[:content][match.to_s[0..-3].to_sym] = "'\"".include?(match.post_match[0]) ? match.post_match[1..-3] : match.post_match[0..-2]
elsif line =~ /^:[a-z]+ ?=> ?/ && structure_began
match = line.match(/^:[a-z]+ ?=> ?/)
structures.last[:content][match.to_s[1..-5].to_sym] = "'\"".include?(match.post_match[0]) ? match.post_match[1..-3] : match.post_match[0..-2]
elsif line == '}'
structure_began = false
else
end
end
end
|