Class: SketchClass
- Inherits:
-
Object
- Object
- SketchClass
- Defined in:
- lib/propane/creators/sketch_class.rb
Overview
the sketch class
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #class_sketch ⇒ Object
- #indent(line) ⇒ Object
-
#initialize(name:, width: 150, height: 150, mode: nil) ⇒ SketchClass
constructor
A new instance of SketchClass.
- #lines ⇒ Object
- #method_lines(name, content = '') ⇒ Object
- #size ⇒ Object
- #sketch_class ⇒ Object
- #sketch_new ⇒ Object
- #sketch_title ⇒ Object
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
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/propane/creators/sketch_class.rb', line 4 def height @height end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
4 5 6 |
# File 'lib/propane/creators/sketch_class.rb', line 4 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/propane/creators/sketch_class.rb', line 4 def name @name end |
#width ⇒ Object (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_sketch ⇒ Object
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 |
#lines ⇒ Object
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 |
#size ⇒ Object
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_class ⇒ Object
14 15 16 |
# File 'lib/propane/creators/sketch_class.rb', line 14 def sketch_class name.split('_').collect(&:capitalize).join end |
#sketch_new ⇒ Object
18 19 20 |
# File 'lib/propane/creators/sketch_class.rb', line 18 def sketch_new format('%s.new', sketch_class) end |
#sketch_title ⇒ Object
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 |