Class: DataFormatter::Indentation
- Inherits:
-
Object
- Object
- DataFormatter::Indentation
- Defined in:
- lib/data_formatter/indentation.rb
Constant Summary collapse
- INDENT_CHARS =
" "
Instance Attribute Summary collapse
-
#indent_level ⇒ Object
Returns the value of attribute indent_level.
Instance Method Summary collapse
- #decrease ⇒ Object
- #increase ⇒ Object
- #indent(value) ⇒ Object
-
#initialize(args = {}) ⇒ Indentation
constructor
A new instance of Indentation.
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Indentation
Returns a new instance of Indentation.
8 9 10 |
# File 'lib/data_formatter/indentation.rb', line 8 def initialize(args={}) @indent_level = args.fetch(:indent_level, 0) end |
Instance Attribute Details
#indent_level ⇒ Object
Returns the value of attribute indent_level.
6 7 8 |
# File 'lib/data_formatter/indentation.rb', line 6 def indent_level @indent_level end |
Instance Method Details
#decrease ⇒ Object
20 21 22 |
# File 'lib/data_formatter/indentation.rb', line 20 def decrease self.indent_level = [indent_level - 1, 0].max end |
#increase ⇒ Object
16 17 18 |
# File 'lib/data_formatter/indentation.rb', line 16 def increase self.indent_level += 1 end |
#indent(value) ⇒ Object
12 13 14 |
# File 'lib/data_formatter/indentation.rb', line 12 def indent(value) to_s + value.to_s end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/data_formatter/indentation.rb', line 24 def to_s INDENT_CHARS * indent_level end |