Sha256: a44bb32e0fbcd5fe6990ab56f8b4138acd32ed3c22270a5b5d1cd2d95125f00c

Contents?: true

Size: 1018 Bytes

Versions: 6

Compression:

Stored size: 1018 Bytes

Contents

require_relative './helpers/camel_string'
require_relative './helpers/string_extra'

module Processing
  # Wraps bare sketch with class wrapper etc
  class Writer
    attr_reader :code, :file
    REQ = "require 'jruby_art'\n\n"
    KLASS = "class %s < %s \n\n"

    def initialize
      @code = []
      code << REQ
    end

    def read(input)
      @file = input
      source = File.read(input)
      default = source.match(/P(2|3)D/).nil?
      name = File.basename(input).sub(/(\.rb)$/, '')
      mode = default ? 'Processing::App' : 'Processing::AppGL'
      camel_name = CamelString.new(name).camelize
      code << format(KLASS, camel_name, mode)
      IO.foreach(input) do |line|
        code << format('  %s', line)
      end
      code << "end\n\n"
      title = StringExtra.new(name).titleize
      code << "#{camel_name}.new(title: \"#{title}\")"
    end

    def write
      File.open(file, 'w:UTF-8') do |out|
        code.each do |line|
          out.write(line)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jruby_art-0.2.6.pre lib/jruby_art/writer.rb
jruby_art-0.2.4.pre lib/jruby_art/writer.rb
jruby_art-0.2.3.pre lib/jruby_art/writer.rb
jruby_art-0.2.2.pre lib/jruby_art/writer.rb
jruby_art-0.2.1.pre lib/jruby_art/writer.rb
jruby_art-0.2.0.pre lib/jruby_art/writer.rb