Class: SuperDiff::RSpec::MatcherTextTemplate

Inherits:
Object
  • Object
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

#initializeMatcherTextTemplate

Returns a new instance of MatcherTextTemplate.



10
11
12
13
14
15
16
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 10

def initialize
  @tokens = []

  if block_given?
    yield self
  end
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



38
39
40
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 38

def add_break(*args, &block)
  add_token(Break, *args, &block)
end

#add_list_in_color(*args, &block) ⇒ Object



34
35
36
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 34

def add_list_in_color(*args, &block)
  add_token(ColorizedList, *args, &block)
end

#add_text(*args, &block) ⇒ Object



18
19
20
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 18

def add_text(*args, &block)
  add_token(PlainText, *args, &block)
end

#add_text_in_color(*args, &block) ⇒ Object



22
23
24
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 22

def add_text_in_color(*args, &block)
  add_token(ColorizedText, *args, &block)
end

#add_text_in_multiline_mode(*args, &block) ⇒ Object



30
31
32
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 30

def add_text_in_multiline_mode(*args, &block)
  add_token(PlainTextInMultilineMode, *args, &block)
end

#add_text_in_singleline_mode(*args, &block) ⇒ Object



26
27
28
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 26

def add_text_in_singleline_mode(*args, &block)
  add_token(PlainTextInSinglelineMode, *args, &block)
end

#insert(*args, &block) ⇒ Object



42
43
44
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 42

def insert(*args, &block)
  add_token(Insertion, *args, &block)
end

#length_of_first_paragraphObject



46
47
48
49
50
51
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 46

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



53
54
55
56
57
58
59
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 53

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_modeObject



65
66
67
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 65

def to_string_in_multiline_mode
  tokens.map(&:to_string_in_multiline_mode).join
end

#to_string_in_singleline_modeObject



61
62
63
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 61

def to_string_in_singleline_mode
  tokens.map(&:to_string_in_singleline_mode).join
end