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

Version Path
picrate-2.5.2-java lib/picrate/creators/sketch_writer.rb
picrate-2.5.1-java lib/picrate/creators/sketch_writer.rb
picrate-2.5.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.4.2-java lib/picrate/creators/sketch_writer.rb
picrate-2.4.1-java lib/picrate/creators/sketch_writer.rb
picrate-2.4.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.3.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.2.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.1.2-java lib/picrate/creators/sketch_writer.rb
picrate-2.1.1-java lib/picrate/creators/sketch_writer.rb
picrate-2.1.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.0.1-java lib/picrate/creators/sketch_writer.rb
picrate-1.3.0-java lib/picrate/creators/sketch_writer.rb
picrate-2.0.0.pre-java lib/picrate/creators/sketch_writer.rb
picrate-1.2.4-java lib/picrate/creators/sketch_writer.rb
picrate-1.2.3-java lib/picrate/creators/sketch_writer.rb
picrate-1.2.2-java lib/picrate/creators/sketch_writer.rb
picrate-1.2.1-java lib/picrate/creators/sketch_writer.rb
picrate-1.2.0-java lib/picrate/creators/sketch_writer.rb
picrate-1.1.0-java lib/picrate/creators/sketch_writer.rb