class Puppet::Pops::Types::PRegexpType

@api public

Constants

DEFAULT

Attributes

pattern[R]

Public Class Methods

append_flags_group(rx_string, options) click to toggle source
     # File lib/puppet/pops/types/types.rb
1712 def self.append_flags_group(rx_string, options)
1713   if options == 0
1714     rx_string
1715   else
1716     bld = String.new('(?')
1717     bld << 'i' if (options & Regexp::IGNORECASE) != 0
1718     bld << 'm' if (options & Regexp::MULTILINE) != 0
1719     bld << 'x' if (options & Regexp::EXTENDED) != 0
1720     unless options == (Regexp::IGNORECASE | Regexp::MULTILINE | Regexp::EXTENDED)
1721       bld << '-'
1722       bld << 'i' if (options & Regexp::IGNORECASE) == 0
1723       bld << 'm' if (options & Regexp::MULTILINE) == 0
1724       bld << 'x' if (options & Regexp::EXTENDED) == 0
1725     end
1726     bld << ':' << rx_string << ')'
1727     bld.freeze
1728   end
1729 end
new(pattern) click to toggle source
     # File lib/puppet/pops/types/types.rb
1731 def initialize(pattern)
1732   if pattern.is_a?(Regexp)
1733     @regexp = pattern
1734     @pattern = PRegexpType.regexp_to_s(pattern)
1735   else
1736     @pattern = pattern
1737   end
1738 end
new_function(type) click to toggle source

Returns a new function that produces a Regexp instance

     # File lib/puppet/pops/types/types.rb
1685 def self.new_function(type)
1686   @new_function ||= Puppet::Functions.create_loaded_function(:new_float, type.loader) do
1687     dispatch :from_string do
1688       param 'String', :pattern
1689       optional_param 'Boolean', :escape
1690     end
1691 
1692     def from_string(pattern, escape = false)
1693       Regexp.new(escape ? Regexp.escape(pattern) : pattern)
1694     end
1695   end
1696 end
regexp_to_s(regexp) click to toggle source

@param regexp [Regexp] the regular expression @return [String] the Regexp as a string without escaped slash

     # File lib/puppet/pops/types/types.rb
1708 def self.regexp_to_s(regexp)
1709   append_flags_group(regexp.source, regexp.options)
1710 end
regexp_to_s_with_delimiters(regexp) click to toggle source

@param regexp [Regexp] the regular expression @return [String] the Regexp as a slash delimited string with slashes escaped

     # File lib/puppet/pops/types/types.rb
1702 def self.regexp_to_s_with_delimiters(regexp)
1703   regexp.options == 0 ? regexp.inspect : "/#{regexp}/"
1704 end
register_ptype(loader, ir) click to toggle source
     # File lib/puppet/pops/types/types.rb
1674 def self.register_ptype(loader, ir)
1675   create_ptype(loader, ir, 'ScalarType',
1676     'pattern' => {
1677       KEY_TYPE => PVariantType.new([PUndefType::DEFAULT, PStringType::DEFAULT, PRegexpType::DEFAULT]),
1678       KEY_VALUE => nil
1679     })
1680 end

Public Instance Methods

eql?(o) click to toggle source
     # File lib/puppet/pops/types/types.rb
1748 def eql?(o)
1749   self.class == o.class && @pattern == o.pattern
1750 end
from_string(pattern, escape = false) click to toggle source
     # File lib/puppet/pops/types/types.rb
1692 def from_string(pattern, escape = false)
1693   Regexp.new(escape ? Regexp.escape(pattern) : pattern)
1694 end
hash() click to toggle source
     # File lib/puppet/pops/types/types.rb
1744 def hash
1745   @pattern.hash
1746 end
instance?(o, guard=nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1752 def instance?(o, guard=nil)
1753   o.is_a?(Regexp) && @pattern.nil? || regexp == o
1754 end
regexp() click to toggle source
     # File lib/puppet/pops/types/types.rb
1740 def regexp
1741   @regexp ||= Regexp.new(@pattern || '')
1742 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

     # File lib/puppet/pops/types/types.rb
1762 def _assignable?(o, guard)
1763   o.is_a?(PRegexpType) && (@pattern.nil? || @pattern == o.pattern)
1764 end