Class: Tzispa::Utils::Indenter
- Inherits:
-
Object
- Object
- Tzispa::Utils::Indenter
- Defined in:
- lib/tzispa/utils/indenter.rb
Constant Summary collapse
- DEFAULT_INDENT_CHAR =
' '- DEFAULT_INDENT_SIZE =
2
Instance Attribute Summary collapse
-
#indent_char ⇒ Object
readonly
Returns the value of attribute indent_char.
-
#instr ⇒ Object
readonly
Returns the value of attribute instr.
-
#sbuff ⇒ Object
readonly
Returns the value of attribute sbuff.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #indent ⇒ Object
-
#initialize(indent_size = nil, indent_char = nil) ⇒ Indenter
constructor
A new instance of Indenter.
- #to_s ⇒ Object
- #unindent ⇒ Object
Constructor Details
#initialize(indent_size = nil, indent_char = nil) ⇒ Indenter
Returns a new instance of Indenter.
16 17 18 19 20 21 |
# File 'lib/tzispa/utils/indenter.rb', line 16 def initialize(indent_size = nil, indent_char = nil) @indent_size = indent_size || DEFAULT_INDENT_SIZE @indent_current = 0 @indent_char = indent_char || DEFAULT_INDENT_CHAR @instr = String.new end |
Instance Attribute Details
#indent_char ⇒ Object (readonly)
Returns the value of attribute indent_char.
14 15 16 |
# File 'lib/tzispa/utils/indenter.rb', line 14 def indent_char @indent_char end |
#instr ⇒ Object (readonly)
Returns the value of attribute instr.
14 15 16 |
# File 'lib/tzispa/utils/indenter.rb', line 14 def instr @instr end |
#sbuff ⇒ Object (readonly)
Returns the value of attribute sbuff.
14 15 16 |
# File 'lib/tzispa/utils/indenter.rb', line 14 def sbuff @sbuff end |
Instance Method Details
#<<(item) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tzispa/utils/indenter.rb', line 23 def <<(item) ss = item.to_s.indentize(@indent_current, @indent_char) @instr.concat ss self end |
#indent ⇒ Object
34 35 36 37 38 |
# File 'lib/tzispa/utils/indenter.rb', line 34 def indent @indent_current += @indent_size self end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/tzispa/utils/indenter.rb', line 30 def to_s @instr end |
#unindent ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/tzispa/utils/indenter.rb', line 40 def unindent if (@indent_current - @indent_size).positive? @indent_current -= @indent_size else @indent_current = 0 end self end |