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.



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

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



461
462
463
464
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 461

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.



466
467
468
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 466

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.



470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 470

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.



456
457
458
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 456

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