class SuperDiff::RSpec::MatcherTextTemplate::Text

Attributes

block[R]
immediate_value[R]

Public Class Methods

new(immediate_value = nil, &block) click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 96
def initialize(immediate_value = nil, &block)
  @immediate_value = immediate_value
  @block = block
end

Public Instance Methods

to_s() click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 109
def to_s
  raise NotImplementedError.new("#{self.class} must support #to_s")
end
to_string_in_multiline_mode() click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 105
def to_string_in_multiline_mode
  to_s
end
to_string_in_singleline_mode() click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 101
def to_string_in_singleline_mode
  to_s
end

Protected Instance Methods

evaluate() click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 117
def evaluate
  if immediate_value && block
    raise ArgumentError.new(
      "Cannot provide both immediate value and block",
    )
  end

  immediate_value || block.call
end
to_sentence(values) click to toggle source
# File lib/super_diff/rspec/matcher_text_template.rb, line 127
def to_sentence(values)
  case values.length
  when 0
    ""
  when 1
    values[0]
  else
    # TODO: Use Oxford comma
    values[0..-2].join(", ") + " and #{values[-1]}"
  end
end