Module: Simply::Indentation

Defined in:
lib/simply/indentation.rb

Defined Under Namespace

Classes: IndentationError

Constant Summary collapse

DEFAULT_NUM_SPACES_TO_INDENT =
2
DEFAULT_INDENTATION_LEVEL =
0

Instance Method Summary collapse

Instance Method Details

#<<(text) ⇒ Object



14
15
16
17
18
19
# File 'lib/simply/indentation.rb', line 14

def <<(text)
  out = empty? ? "" : "\n"
  out << "#{" " * indentation_level}#{text}"
  
  super(out)
end

#indent(number_of_spaces = DEFAULT_NUM_SPACES_TO_INDENT) ⇒ Object



21
22
23
24
# File 'lib/simply/indentation.rb', line 21

def indent(number_of_spaces = DEFAULT_NUM_SPACES_TO_INDENT)
  @indentation_level ||= DEFAULT_INDENTATION_LEVEL
  @indentation_level += number_of_spaces
end

#indentation_levelObject



33
34
35
# File 'lib/simply/indentation.rb', line 33

def indentation_level
  @indentation_level ||= DEFAULT_INDENTATION_LEVEL
end

#outdent(number_of_spaces = DEFAULT_NUM_SPACES_TO_INDENT) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/simply/indentation.rb', line 26

def outdent(number_of_spaces = DEFAULT_NUM_SPACES_TO_INDENT)
  @indentation_level ||= DEFAULT_INDENTATION_LEVEL
  @indentation_level -= number_of_spaces
  raise IndentationError if @indentation_level < 0
  @indentation_level
end