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.



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

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

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#class_sketchObject



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

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

#indent(line) ⇒ Object



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

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

#linesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/propane/creators/sketch_class.rb', line 41

def lines
  lines = [
    '# 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

#method_lines(name, content = '') ⇒ Object



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

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

#sizeObject



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

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

#sketch_classObject



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

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

#sketch_newObject



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

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

#sketch_titleObject



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

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