Class: Clive::Formatter Abstract
- Inherits:
-
Object
- Object
- Clive::Formatter
- Defined in:
- lib/clive/formatter.rb,
lib/clive/formatter/plain.rb,
lib/clive/formatter/colour.rb
Overview
This class is abstract.
Subclass and override #to_s (and probably #initialize) to implement a custom Formatter. #initialize should take an options hash.
Takes care of formatting the help string. Look at Plain for a good (if not a bit complex) reference of how to do it.
Then it is just a case of passing an instance of the new formatter to run. You can use a different formatter for commands by passing it when creating them.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#commands ⇒ Object
writeonly
Sets the attribute commands.
-
#footer ⇒ Object
writeonly
Sets the attribute footer.
-
#header ⇒ Object
writeonly
Sets the attribute header.
-
#options ⇒ Object
writeonly
Sets the attribute options.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Formatter
constructor
A new instance of Formatter.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Formatter
Returns a new instance of Formatter.
45 46 47 48 49 50 |
# File 'lib/clive/formatter.rb', line 45 def initialize(opts={}) @opts = opts @header, @footer = '', '' @commands, @options = [], [] end |
Instance Attribute Details
#commands=(value) ⇒ Object (writeonly)
Sets the attribute commands
43 44 45 |
# File 'lib/clive/formatter.rb', line 43 def commands=(value) @commands = value end |
#footer=(value) ⇒ Object (writeonly)
Sets the attribute footer
43 44 45 |
# File 'lib/clive/formatter.rb', line 43 def (value) @footer = value end |
#header=(value) ⇒ Object (writeonly)
Sets the attribute header
43 44 45 |
# File 'lib/clive/formatter.rb', line 43 def header=(value) @header = value end |
#options=(value) ⇒ Object (writeonly)
Sets the attribute options
43 44 45 |
# File 'lib/clive/formatter.rb', line 43 def (value) @options = value end |
Instance Method Details
#inspect ⇒ Object
56 57 58 |
# File 'lib/clive/formatter.rb', line 56 def inspect "#<#{self.class.name} @opts=#@opts>" end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/clive/formatter.rb', line 52 def to_s ([@header] + @commands + @options + [@footer]).join("\n") end |