Class: DataFormatter::Indentation

Inherits:
Object
  • Object
show all
Defined in:
lib/data_formatter/indentation.rb

Constant Summary collapse

INDENT_CHARS =
"  "

Instance Attribute Summary collapse

Instance Method Summary collapse

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_levelObject

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

#decreaseObject



20
21
22
# File 'lib/data_formatter/indentation.rb', line 20

def decrease
  self.indent_level = [indent_level - 1, 0].max
end

#increaseObject



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_sObject



24
25
26
# File 'lib/data_formatter/indentation.rb', line 24

def to_s
  INDENT_CHARS * indent_level 
end