Module: Ace::Demo::Atoms::TapeContentGenerator

Defined in:
lib/ace/demo/atoms/tape_content_generator.rb

Class Method Summary collapse

Class Method Details

.generate(name:, commands:, description: nil, tags: nil, output_path: nil, font_size: 16, width: 960, height: 480, timeout: "2s") ⇒ Object



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
# File 'lib/ace/demo/atoms/tape_content_generator.rb', line 9

def generate(name:, commands:, description: nil, tags: nil, output_path: nil,
  font_size: 16, width: 960, height: 480, timeout: "2s")
  lines = []

  lines << "# Description: #{description}" if description
  lines << "# Tags: #{tags}" if tags
  lines << "" if description || tags

  output = output_path || ".ace-local/demo/#{name}.gif"
  lines << "Output #{output}"
  lines << ""
  lines << "Set FontSize #{font_size}"
  lines << "Set Width #{width}"
  lines << "Set Height #{height}"

  commands.each do |cmd|
    escaped = cmd.gsub("\\", "\\\\\\\\").gsub('"', '\\"')
    lines << ""
    lines << "Type \"#{escaped}\""
    lines << "Enter"
    lines << "Sleep #{timeout}"
  end

  lines.join("\n") + "\n"
end