class Puppet::Pops::Types::PEnumType

A string type describing the set of strings having one of the given values @api public

Constants

DEFAULT

Attributes

case_insensitive[R]
values[R]

Public Class Methods

new(values, case_insensitive = false) click to toggle source
    # File lib/puppet/pops/types/types.rb
768 def initialize(values, case_insensitive = false)
769   @values = values.uniq.sort.freeze
770   @case_insensitive = case_insensitive
771 end
register_ptype(loader, ir) click to toggle source
    # File lib/puppet/pops/types/types.rb
760 def self.register_ptype(loader, ir)
761   create_ptype(loader, ir, 'ScalarDataType',
762     'values' => PArrayType.new(PStringType::NON_EMPTY),
763     'case_insensitive' => { 'type' => PBooleanType::DEFAULT, 'value' => false })
764 end

Public Instance Methods

case_insensitive?() click to toggle source
    # File lib/puppet/pops/types/types.rb
773 def case_insensitive?
774   @case_insensitive
775 end
each(&block) click to toggle source

Returns Enumerator if no block is given, otherwise, calls the given block with each of the strings for this enum

    # File lib/puppet/pops/types/types.rb
779 def each(&block)
780   r = Iterable.on(self)
781   block_given? ? r.each(&block) : r
782 end
eql?(o) click to toggle source
    # File lib/puppet/pops/types/types.rb
807 def eql?(o)
808   self.class == o.class && @values == o.values && @case_insensitive == o.case_insensitive?
809 end
generalize() click to toggle source
    # File lib/puppet/pops/types/types.rb
784 def generalize
785   # General form of an Enum is a String
786   if @values.empty?
787     PStringType::DEFAULT
788   else
789     range = @values.map(&:size).minmax
790     PStringType.new(PIntegerType.new(range.min, range.max))
791   end
792 end
hash() click to toggle source
    # File lib/puppet/pops/types/types.rb
803 def hash
804   @values.hash ^ @case_insensitive.hash
805 end
instance?(o, guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
811 def instance?(o, guard = nil)
812   if o.is_a?(String)
813     @case_insensitive ? @values.any? { |p| p.casecmp(o) == 0 } : @values.any? { |p| p == o }
814   else
815     false
816   end
817 end
iterable?(guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
794 def iterable?(guard = nil)
795   true
796 end
iterable_type(guard = nil) click to toggle source
    # File lib/puppet/pops/types/types.rb
798 def iterable_type(guard = nil)
799   # An instance of an Enum is a String
800   PStringType::ITERABLE_TYPE
801 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

    # File lib/puppet/pops/types/types.rb
824 def _assignable?(o, guard)
825   return true if self == o
826   svalues = values
827   if svalues.empty?
828     return true if o.is_a?(PStringType) || o.is_a?(PEnumType) || o.is_a?(PPatternType)
829   end
830   case o
831     when PStringType
832       # if the contained string is found in the set of enums
833       instance?(o.value, guard)
834     when PEnumType
835       !o.values.empty? && (case_insensitive? || !o.case_insensitive?) && o.values.all? { |s| instance?(s, guard) }
836     else
837       false
838   end
839 end