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 = nil) ⇒ 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.
7 8 9 |
# File 'lib/propane/creators/sketch_class.rb', line 7 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.
5 6 7 |
# File 'lib/propane/creators/sketch_class.rb', line 5 def height @height end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
5 6 7 |
# File 'lib/propane/creators/sketch_class.rb', line 5 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/propane/creators/sketch_class.rb', line 5 def name @name end |
#width ⇒ Object (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_sketch ⇒ Object
11 12 13 |
# File 'lib/propane/creators/sketch_class.rb', line 11 def class_sketch format('class %s < Propane::App', sketch_class) end |
#indent(line) ⇒ Object
23 24 25 |
# File 'lib/propane/creators/sketch_class.rb', line 23 def indent(line) format(' %s', line) end |
#lines ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/propane/creators/sketch_class.rb', line 42 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
37 38 39 40 |
# File 'lib/propane/creators/sketch_class.rb', line 37 def method_lines(name, content = nil) return [format(' def %s', name), '', ' end'] unless content [format(' def %s', name), content, ' end', ''] end |
#size ⇒ Object
27 28 29 30 |
# File 'lib/propane/creators/sketch_class.rb', line 27 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_class ⇒ Object
15 16 17 |
# File 'lib/propane/creators/sketch_class.rb', line 15 def sketch_class name.split('_').collect(&:capitalize).join end |
#sketch_new ⇒ Object
19 20 21 |
# File 'lib/propane/creators/sketch_class.rb', line 19 def sketch_new format('%s.new', sketch_class) end |
#sketch_title ⇒ Object
32 33 34 35 |
# File 'lib/propane/creators/sketch_class.rb', line 32 def sketch_title human = name.split('_').collect(&:capitalize).join(' ') format(" sketch_title '%s'", human) end |