Class: Build::Text::Indentation

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

Constant Summary collapse

TAB =
"\t".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, level, indent) ⇒ Indentation

Returns a new instance of Indentation.



26
27
28
29
30
# File 'lib/build/text/indentation.rb', line 26

def initialize(prefix, level, indent)
	@prefix = prefix
	@level = level
	@indent = indent
end

Class Method Details

.noneObject



62
63
64
# File 'lib/build/text/indentation.rb', line 62

def self.none
	self.new('', 0, TAB)
end

Instance Method Details

#+(other) ⇒ Object



46
47
48
# File 'lib/build/text/indentation.rb', line 46

def + other
	indentation + other
end

#<<(text) ⇒ Object



50
51
52
# File 'lib/build/text/indentation.rb', line 50

def << text
	text.gsub(/^/){|m| m + indentation}
end

#by(depth) ⇒ Object



54
55
56
# File 'lib/build/text/indentation.rb', line 54

def by(depth)
	Indentation.new(@prefix, @level + depth, @indent)
end

#freezeObject



32
33
34
35
36
37
38
39
40
# File 'lib/build/text/indentation.rb', line 32

def freeze
	indentation
	
	@prefix.freeze
	@level.freeze
	@indent.freeze
	
	super
end

#indentationObject



42
43
44
# File 'lib/build/text/indentation.rb', line 42

def indentation
	@indentation ||= @prefix + (@indent * @level)
end

#with_prefix(prefix) ⇒ Object



58
59
60
# File 'lib/build/text/indentation.rb', line 58

def with_prefix(prefix)
	Indentation.new(prefix, @level, @indent)
end