Sha256: 90aae2fbb638ef010abc9db853f82bb3b7438bb9b569a255ddf477ea3c00099e

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

#frozen_string_literal: false
# the sketch class
class SketchClass
  attr_reader :name, :width, :height, :mode

  def initialize(name:, width: 150, height: 150, mode: nil)
    @name, @width, @height, @mode = name, width, height, mode
  end

  def class_sketch
    format('class %s < Propane::App', sketch_class)
  end

  def sketch_class
    name.split('_').collect(&:capitalize).join
  end

  def sketch_new
    format('%s.new', sketch_class)
  end

  def indent(line)
    format('  %s', line)
  end

  def size
    return format('    size %d, %d', width.to_i, height.to_i) if mode.nil?
    format('    size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
  end

  def sketch_title
    human = name.split('_').collect(&:capitalize).join(' ')
    format("    sketch_title '%s'", human)
  end

  def method_lines(name, content = '')
    return [format('  def %s', name), content, '  end'] if content.empty?
    [format('  def %s', name), content, '  end', '']
  end

  def lines
    lines = [
      '#!/usr/bin/env jruby',
      '# frozen_string_literal: false',
      "require 'propane'",
      '',
      class_sketch
    ]
    lines.concat method_lines('settings', size)
    lines.concat method_lines('setup', sketch_title)
    lines.concat method_lines('draw')
    lines << 'end'
    lines << sketch_new
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
propane-2.3.4-java lib/propane/creators/sketch_class.rb
propane-2.3.3-java lib/propane/creators/sketch_class.rb
propane-2.4.0.pre-java lib/propane/creators/sketch_class.rb
propane-2.3.2-java lib/propane/creators/sketch_class.rb
propane-2.3.1-java lib/propane/creators/sketch_class.rb