Class: SketchClass

Inherits:
Object
  • Object
show all
Defined in:
lib/propane/creators/sketch_class.rb

Overview

the sketch class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, width: 150, height: 150, mode: nil) ⇒ SketchClass

Returns a new instance of SketchClass.



7
8
9
10
11
12
# File 'lib/propane/creators/sketch_class.rb', line 7

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

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/propane/creators/sketch_class.rb', line 5

def height
  @height
end

#modeObject (readonly)

Returns the value of attribute mode.



5
6
7
# File 'lib/propane/creators/sketch_class.rb', line 5

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/propane/creators/sketch_class.rb', line 5

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/propane/creators/sketch_class.rb', line 5

def width
  @width
end

Instance Method Details

#class_sketchObject



14
15
16
# File 'lib/propane/creators/sketch_class.rb', line 14

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

#indent(line) ⇒ Object



26
27
28
# File 'lib/propane/creators/sketch_class.rb', line 26

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

#linesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/propane/creators/sketch_class.rb', line 47

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 << ''
  lines << sketch_new
end

#method_lines(name, content = nil) ⇒ Object



41
42
43
44
45
# File 'lib/propane/creators/sketch_class.rb', line 41

def method_lines(name, content = nil)
  return [format('  def %s', name), '', '  end'] unless content

  [format('  def %s', name), content, '  end', '']
end

#sizeObject



30
31
32
33
34
# File 'lib/propane/creators/sketch_class.rb', line 30

def size
  return format('    size %d, %d', width.to_i, height.to_i) unless mode

  format('    size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
end

#sketch_classObject



18
19
20
# File 'lib/propane/creators/sketch_class.rb', line 18

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

#sketch_newObject



22
23
24
# File 'lib/propane/creators/sketch_class.rb', line 22

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

#sketch_titleObject



36
37
38
39
# File 'lib/propane/creators/sketch_class.rb', line 36

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