Class: Puppet::Pops::Types::SizeMismatch Private

Inherits:
ExpectedActualMismatch show all
Defined in:
lib/puppet/pops/types/type_mismatch_describer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

CountMismatch

Instance Attribute Summary

Attributes inherited from ExpectedActualMismatch

#actual, #expected

Attributes inherited from Mismatch

#path

Instance Method Summary collapse

Methods inherited from ExpectedActualMismatch

#==, #hash, #initialize

Methods inherited from Mismatch

#==, #canonical_path, #chop_path, #eql?, #format, #hash, #initialize, #path_string, #to_s

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::ExpectedActualMismatch

Instance Method Details

#fromObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



439
440
441
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 439

def from
  @expected.from || 0
end

#merge(path, o) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A new instance with the least restrictive respective boundaries.

Returns:

  • A new instance with the least restrictive respective boundaries



448
449
450
451
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 448

def merge(path, o)
  range = PIntegerType.new(from < o.from ? from : o.from, to > o.to ? to : o.to)
  self.class.new(path, range, @actual)
end

#message(variant, position) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



453
454
455
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 453

def message(variant, position)
  "#{variant}#{position} expects size to be #{range_to_s(expected, '0')}, got #{range_to_s(actual, '0')}"
end

#range_to_s(range, zero_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 457

def range_to_s(range, zero_string)
  min = range.from || 0
  max = range.to || Float::INFINITY
  if min == max
    min == 0 ? zero_string : min.to_s
  elsif min == 0
    max == Float::INFINITY ? 'unlimited' : "at most #{max}"
  elsif max == Float::INFINITY
    "at least #{min}"
  else
    "between #{min} and #{max}"
  end
end

#toObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



443
444
445
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 443

def to
  @expected.to || Float::INFINITY
end