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 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
#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
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 |
#lines ⇒ Object
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 |
#size ⇒ Object
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_class ⇒ Object
18 19 20 |
# File 'lib/propane/creators/sketch_class.rb', line 18 def sketch_class name.split('_').collect(&:capitalize).join end |
#sketch_new ⇒ Object
22 23 24 |
# File 'lib/propane/creators/sketch_class.rb', line 22 def sketch_new format('%s.new', sketch_class) end |
#sketch_title ⇒ Object
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 |