Sha256: 3d4666382e4a50ceac7d2a656b01290d8690d87969198a6b8e4fb77bb221a551
Contents?: true
Size: 1.19 KB
Versions: 20
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true require_relative 'parameters' require 'erb' TEMPLATE = ERB.new <<~SKETCH require 'picrate' class <%= @class %> < Processing::App def settings size <%= @width %>, <%= @height %>, <%= @mode %> end def setup end def draw end end <%= @class %>.new SKETCH # The SketchClass class knows how to format title & class name class SketchClass attr_reader :name def initialize(name) @name = name end def class_name name.split('_').collect(&:capitalize).join end # def title # name.split('_').collect(&:capitalize).join(' ') # end def filename name << '.rb' end end # The file writer can write a sketch when given instance of Sketch type class SketchWriter attr_reader :file, :name, :width, :height, :mode, :sketch def initialize(path) param = Parameters.read @sketch = SketchClass.new(path) @class = sketch.class_name sketch_param = param.fetch('sketch') @width = sketch_param.fetch('width') @height = sketch_param.fetch('height') @mode = sketch_param.fetch('mode') binding end def write File.open(sketch.filename, 'w+') { |f| f.write TEMPLATE.result(binding) } end end
Version data entries
20 entries across 20 versions & 1 rubygems