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))
ITERABLE_TYPE =

Iterates over each character of the string

PIterableType.new(PStringType.new(PIntegerType.new(1,1)))

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PAnyType

#==, #assignable?, #callable?, #callable_args?, #kind_of_callable?, #normalize, #simple_name, #to_alias_expanded_s, #to_s

Constructor Details

#initialize(size_type, values = EMPTY_ARRAY) ⇒ PStringType

Returns a new instance of PStringType.



946
947
948
949
# File 'lib/puppet/pops/types/types.rb', line 946

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

Instance Attribute Details

#size_typeObject (readonly)



944
945
946
# File 'lib/puppet/pops/types/types.rb', line 944

def size_type
  @size_type
end

#valuesObject (readonly)



944
945
946
# File 'lib/puppet/pops/types/types.rb', line 944

def values
  @values
end

Instance Method Details

#accept(visitor, guard) ⇒ Object



951
952
953
954
# File 'lib/puppet/pops/types/types.rb', line 951

def accept(visitor, guard)
  super
  @size_type.accept(visitor, guard) unless @size_type.nil?
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


972
973
974
# File 'lib/puppet/pops/types/types.rb', line 972

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

#generalizeObject



956
957
958
# File 'lib/puppet/pops/types/types.rb', line 956

def generalize
  DEFAULT
end

#hashObject



960
961
962
# File 'lib/puppet/pops/types/types.rb', line 960

def hash
  @size_type.hash ^ @values.hash
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


976
977
978
979
980
981
982
983
# File 'lib/puppet/pops/types/types.rb', line 976

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

#iterable?(guard = nil) ⇒ Boolean

Returns:

  • (Boolean)


964
965
966
# File 'lib/puppet/pops/types/types.rb', line 964

def iterable?(guard = nil)
  true
end

#iterable_type(guard = nil) ⇒ Object



968
969
970
# File 'lib/puppet/pops/types/types.rb', line 968

def iterable_type(guard = nil)
  ITERABLE_TYPE
end