Class: Puppet::Pops::Types::PEnumType
Overview
A string type describing the set of strings having one of the given values
Constant Summary
collapse
- DEFAULT =
PEnumType.new(EMPTY_ARRAY)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PAnyType
#==, #accept, #assignable?, #callable?, #callable_args?, #callable_with?, #check_self_recursion, #create, #kind_of_callable?, #name, #new_function, new_function, #normalize, #really_instance?, #resolve, simple_name, #simple_name, #to_alias_expanded_s, #to_s
_ptype, create_ptype, register_ptypes
Methods included from Visitable
#accept
#_ptype
Constructor Details
#initialize(values) ⇒ PEnumType
Returns a new instance of PEnumType.
714
715
716
|
# File 'lib/puppet/pops/types/types.rb', line 714
def initialize(values)
@values = values.uniq.sort.freeze
end
|
Instance Attribute Details
712
713
714
|
# File 'lib/puppet/pops/types/types.rb', line 712
def values
@values
end
|
Class Method Details
.register_ptype(loader, ir) ⇒ Object
708
709
710
|
# File 'lib/puppet/pops/types/types.rb', line 708
def self.register_ptype(loader, ir)
create_ptype(loader, ir, 'ScalarType', 'values' => PArrayType.new(PStringType::NON_EMPTY))
end
|
Instance Method Details
#each(&block) ⇒ Object
Returns Enumerator if no block is given, otherwise, calls the given block with each of the strings for this enum
720
721
722
723
|
# File 'lib/puppet/pops/types/types.rb', line 720
def each(&block)
r = Iterable.on(self)
block_given? ? r.each(&block) : r
end
|
#eql?(o) ⇒ Boolean
748
749
750
|
# File 'lib/puppet/pops/types/types.rb', line 748
def eql?(o)
self.class == o.class && @values == o.values
end
|
#generalize ⇒ Object
725
726
727
728
729
730
731
732
733
|
# File 'lib/puppet/pops/types/types.rb', line 725
def generalize
if @values.empty?
PStringType::DEFAULT
else
range = @values.map(&:size).minmax
PStringType.new(PIntegerType.new(range.min, range.max))
end
end
|
744
745
746
|
# File 'lib/puppet/pops/types/types.rb', line 744
def hash
@values.hash
end
|
#instance?(o, guard = nil) ⇒ Boolean
752
753
754
|
# File 'lib/puppet/pops/types/types.rb', line 752
def instance?(o, guard = nil)
o.is_a?(String) && @values.any? { |p| p == o }
end
|
#iterable?(guard = nil) ⇒ Boolean
735
736
737
|
# File 'lib/puppet/pops/types/types.rb', line 735
def iterable?(guard = nil)
true
end
|
#iterable_type(guard = nil) ⇒ Object
739
740
741
742
|
# File 'lib/puppet/pops/types/types.rb', line 739
def iterable_type(guard = nil)
PStringType::ITERABLE_TYPE
end
|