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

#initialize {|_self| ... } ⇒ MatcherTextTemplate

Returns a new instance of MatcherTextTemplate.

Yields:

  • (_self)

Yield Parameters:



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

def initialize
  @tokens = []

  yield self if block_given?
end

Class Method Details

.render(&block) ⇒ Object



8
9
10
# File 'lib/super_diff/rspec/matcher_text_template.rb', line 8

def self.render(&block)
  new(&block).to_s
end

Instance Method Details

#add_breakObject



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

def add_break(...)
  add_token(Break, ...)
end

#add_list_in_colorObject



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

def add_list_in_color(...)
  add_token(ColorizedList, ...)
end

#add_textObject



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

def add_text(...)
  add_token(PlainText, ...)
end

#add_text_in_colorObject



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

def add_text_in_color(...)
  add_token(ColorizedText, ...)
end

#add_text_in_multiline_modeObject



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

def add_text_in_multiline_mode(...)
  add_token(PlainTextInMultilineMode, ...)
end

#add_text_in_singleline_modeObject



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

def add_text_in_singleline_mode(...)
  add_token(PlainTextInSinglelineMode, ...)
end

#insertObject



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

def insert(...)
  add_token(Insertion, ...)
end

#length_of_first_paragraphObject



46
47
48
# 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



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

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



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

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

#to_string_in_singleline_modeObject



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

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