Class: Ytrbium::String
Instance Method Summary
collapse
Methods inherited from String
#indent_by, #single_line_ending_in_newline?
Constructor Details
#initialize ⇒ String
Returns a new instance of String.
2
3
4
5
6
|
# File 'lib/ytrbium/string.rb', line 2
def initialize
super
@indent = 0
@last_newline = 0
end
|
Instance Method Details
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ytrbium/string.rb', line 8
def <<(str)
@indent = -1 if str.include?("\n")
super.tap do
if @indent == -1
@last_newline = str.rindex("\n")
@indent = 0
end
if @indent == 0 && self[@last_newline..-1] =~ /\n([- ]+)\Z/m
@indent = $1.length
end
end
end
|
#indent_expr(obj) ⇒ Object
21
22
23
|
# File 'lib/ytrbium/string.rb', line 21
def indent_expr(obj)
obj.bare_yaml.indent_by(@indent)
end
|
25
26
27
28
29
30
31
|
# File 'lib/ytrbium/string.rb', line 25
def to_s
if start_with?("---")
self
else
"---\n#{self}"
end
end
|