Class: SuperDiff::RSpec::MatcherTextTemplate
- Inherits:
-
Object
- Object
- SuperDiff::RSpec::MatcherTextTemplate
show all
- Defined in:
- lib/super_diff/rspec/matcher_text_template.rb
Defined Under Namespace
Classes: Base, Break, ColorizedList, ColorizedText, Insertion, PlainText, PlainTextInMultilineMode, PlainTextInSinglelineMode, Text
Constant Summary
collapse
- MAX_LINE_LENGTH =
100
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MatcherTextTemplate.
10
11
12
13
14
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 10
def initialize
@tokens = []
yield self if block_given?
end
|
Class Method Details
.render(&block) ⇒ Object
6
7
8
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 6
def self.render(&block)
new(&block).to_s
end
|
Instance Method Details
#add_break(*args, &block) ⇒ Object
36
37
38
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 36
def add_break(*args, &block)
add_token(Break, *args, &block)
end
|
#add_list_in_color(*args, &block) ⇒ Object
32
33
34
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 32
def add_list_in_color(*args, &block)
add_token(ColorizedList, *args, &block)
end
|
#add_text(*args, &block) ⇒ Object
16
17
18
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 16
def add_text(*args, &block)
add_token(PlainText, *args, &block)
end
|
#add_text_in_color(*args, &block) ⇒ Object
20
21
22
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 20
def add_text_in_color(*args, &block)
add_token(ColorizedText, *args, &block)
end
|
#add_text_in_multiline_mode(*args, &block) ⇒ Object
28
29
30
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 28
def add_text_in_multiline_mode(*args, &block)
add_token(PlainTextInMultilineMode, *args, &block)
end
|
#add_text_in_singleline_mode(*args, &block) ⇒ Object
24
25
26
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 24
def add_text_in_singleline_mode(*args, &block)
add_token(PlainTextInSinglelineMode, *args, &block)
end
|
#insert(*args, &block) ⇒ Object
40
41
42
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 40
def insert(*args, &block)
add_token(Insertion, *args, &block)
end
|
#length_of_first_paragraph ⇒ Object
44
45
46
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 44
def length_of_first_paragraph
Csi.decolorize(to_string_in_singleline_mode).split(/\n\n/).first.length
end
|
#to_s(as_single_line: nil) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 48
def to_s(as_single_line: nil)
if length_of_first_paragraph > MAX_LINE_LENGTH ||
as_single_line == false
to_string_in_multiline_mode
elsif length_of_first_paragraph <= MAX_LINE_LENGTH ||
as_single_line == true
to_string_in_singleline_mode
end
end
|
#to_string_in_multiline_mode ⇒ Object
62
63
64
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 62
def to_string_in_multiline_mode
tokens.map(&:to_string_in_multiline_mode).join
end
|
#to_string_in_singleline_mode ⇒ Object
58
59
60
|
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 58
def to_string_in_singleline_mode
tokens.map(&:to_string_in_singleline_mode).join
end
|