Class: Puppet::Pops::Types::PStringType

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

Constant Summary collapse

DEFAULT =
PStringType.new(nil)
NON_EMPTY =
PStringType.new(PIntegerType.new(1))

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#assignable?, #callable?, #callable_args?, #enumerable?, #kind_of_callable?, #simple_name, #to_s

Methods included from Visitable

#accept

Constructor Details

#initialize(size_type, values = []) ⇒ PStringType

Returns a new instance of PStringType.



621
622
623
624
# File 'lib/puppet/pops/types/types.rb', line 621

def initialize(size_type, values = [])
  @size_type = size_type
  @values = values.sort.freeze
end

Instance Attribute Details

#size_typeObject (readonly)



615
616
617
# File 'lib/puppet/pops/types/types.rb', line 615

def size_type
  @size_type
end

#valuesObject (readonly)



615
616
617
# File 'lib/puppet/pops/types/types.rb', line 615

def values
  @values
end

Instance Method Details

#==(o) ⇒ Object



630
631
632
# File 'lib/puppet/pops/types/types.rb', line 630

def ==(o)
  self.class == o.class && @size_type == o.size_type && @values == o.values
end

#generalizeObject



617
618
619
# File 'lib/puppet/pops/types/types.rb', line 617

def generalize
  DEFAULT
end

#hashObject



626
627
628
# File 'lib/puppet/pops/types/types.rb', line 626

def hash
  @size_type.hash * 31 + @values.hash
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


634
635
636
637
638
639
640
641
# File 'lib/puppet/pops/types/types.rb', line 634

def instance?(o)
  # true if size compliant
  if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size))
    @values.empty? || @values.include?(o)
  else
    false
  end
end