Module: Puppet::Pops::PN

Included in:
Call, List, Literal, Map
Defined in:
lib/puppet/pops/pn.rb

Defined Under Namespace

Classes: Call, Entry, Indent, List, Literal, Map

Constant Summary collapse

KEY_PATTERN =
/^[A-Za-z_-][0-9A-Za-z_-]*$/

Instance Method Summary collapse

Instance Method Details

#==(o) ⇒ Object



18
19
20
# File 'lib/puppet/pops/pn.rb', line 18

def ==(o)
  eql?(o)
end

#as_call(name) ⇒ Object



10
11
12
# File 'lib/puppet/pops/pn.rb', line 10

def as_call(name)
  Call.new(name, self)
end

#as_parametersObject



14
15
16
# File 'lib/puppet/pops/pn.rb', line 14

def as_parameters
  [self]
end

#double_quote(str, bld) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/pops/pn.rb', line 32

def double_quote(str, bld)
  bld << '"'
  str.each_codepoint do |codepoint|
    case codepoint
    when 0x09
      bld << '\\t'
    when 0x0a
      bld << '\\n'
    when 0x0d
      bld << '\\r'
    when 0x22
      bld << '\\"'
    when 0x5c
      bld << '\\\\'
    else
      if codepoint < 0x20
        bld << sprintf('\\o%3.3o', codepoint)
      elsif codepoint <= 0x7f
        bld << codepoint
      else
        bld << [codepoint].pack('U')
      end
    end
  end
  bld << '"'
end

#format_elements(elements, indent, b) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/puppet/pops/pn.rb', line 59

def format_elements(elements, indent, b)
  elements.each_with_index do |e, i|
    if indent
      b << "\n" << indent.current
    elsif i > 0
      b << ' '
    end
    e.format(indent, b)
  end
end

#pnError(message) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
# File 'lib/puppet/pops/pn.rb', line 6

def pnError(message)
  raise ArgumentError, message
end

#to_sObject



22
23
24
25
26
# File 'lib/puppet/pops/pn.rb', line 22

def to_s
  s = String.new
  format(nil, s)
  s
end

#with_name(name) ⇒ Object



28
29
30
# File 'lib/puppet/pops/pn.rb', line 28

def with_name(name)
  Entry.new(name, self)
end