Class: KissShot::Spec
- Inherits:
-
Object
- Object
- KissShot::Spec
- Defined in:
- lib/kiss_shot/spec.rb
Overview
This is the main class for code generation
Instance Attribute Summary collapse
-
#content ⇒ String
Content.
-
#line_prefix ⇒ String
Line prefix, such as indent, comment etc.
-
#metadata ⇒ Hash
Metadata.
Class Method Summary collapse
-
.run(metadata = {}, script = nil, &block) ⇒ Object
Create a instance of anonymous subclass, and eval instance.
Instance Method Summary collapse
-
#indent_down ⇒ KissShot::Spec
Indent left 2 whitespaces.
-
#indent_up ⇒ KissShot::Spec
Indent right 2 whitespaces.
-
#initialize(metadata = {}) ⇒ KissShot::Spec
constructor
Create a new Spec.
-
#line(input = "") ⇒ KissShot::Spec
Apend line to content, indent prepended.
-
#pop_line_prefix(prefix) ⇒ Object
Pop line prefix.
-
#push_line_prefix(prefix) ⇒ Object
Push line prefix.
-
#raw(input = "", use_line_prefix = false) ⇒ KissShot::Spec
Append raw string to content.
-
#use(mod) ⇒ KissShot::Spec
Use a module, alias for ‘Class#extend`.
Constructor Details
#initialize(metadata = {}) ⇒ KissShot::Spec
Create a new Spec
29 30 31 32 33 |
# File 'lib/kiss_shot/spec.rb', line 29 def initialize( = {}) self. = self.content = "" self.line_prefix = "" end |
Instance Attribute Details
#content ⇒ String
Returns content.
10 11 12 |
# File 'lib/kiss_shot/spec.rb', line 10 def content @content end |
#line_prefix ⇒ String
Returns line prefix, such as indent, comment etc.
12 13 14 |
# File 'lib/kiss_shot/spec.rb', line 12 def line_prefix @line_prefix end |
#metadata ⇒ Hash
Returns metadata.
8 9 10 |
# File 'lib/kiss_shot/spec.rb', line 8 def end |
Class Method Details
.run(metadata = {}, script = nil, &block) ⇒ Object
Create a instance of anonymous subclass, and eval instance
18 19 20 21 22 23 |
# File 'lib/kiss_shot/spec.rb', line 18 def self.run( = {}, script = nil, &block) spec = Class.new(self).new() spec.instance_eval(script) unless script.nil? spec.instance_eval(&block) unless block.nil? spec.content end |
Instance Method Details
#indent_down ⇒ KissShot::Spec
Indent left 2 whitespaces
74 75 76 |
# File 'lib/kiss_shot/spec.rb', line 74 def indent_down pop_line_prefix " " end |
#indent_up ⇒ KissShot::Spec
Indent right 2 whitespaces
67 68 69 |
# File 'lib/kiss_shot/spec.rb', line 67 def indent_up push_line_prefix " " end |
#line(input = "") ⇒ KissShot::Spec
Apend line to content, indent prepended
94 95 96 97 |
# File 'lib/kiss_shot/spec.rb', line 94 def line(input = "") raw input, true raw "\n" end |
#pop_line_prefix(prefix) ⇒ Object
Pop line prefix
57 58 59 60 61 62 |
# File 'lib/kiss_shot/spec.rb', line 57 def pop_line_prefix(prefix) if self.line_prefix.end_with? prefix self.line_prefix = self.line_prefix[0, self.line_prefix.length - prefix.length] end self end |
#push_line_prefix(prefix) ⇒ Object
Push line prefix
48 49 50 51 |
# File 'lib/kiss_shot/spec.rb', line 48 def push_line_prefix(prefix) self.line_prefix += prefix self end |
#raw(input = "", use_line_prefix = false) ⇒ KissShot::Spec
Append raw string to content
83 84 85 86 87 88 |
# File 'lib/kiss_shot/spec.rb', line 83 def raw(input = "", use_line_prefix = false) return unless input.length > 0 self.content += self.line_prefix if use_line_prefix self.content += input.to_s self end |
#use(mod) ⇒ KissShot::Spec
Use a module, alias for ‘Class#extend`
39 40 41 42 |
# File 'lib/kiss_shot/spec.rb', line 39 def use(mod) self.extend mod self end |