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


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

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

#as_call(name) ⇒ Object


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

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

#as_parametersObject


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

def as_parameters
  [self]
end

#double_quote(str, bld) ⇒ Object


31
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
# File 'lib/puppet/pops/pn.rb', line 31

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


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

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)

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

def pnError(message)
  raise ArgumentError, message
end

#to_sObject


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

def to_s
  s = ''
  format(nil, s)
  s
end

#with_name(name) ⇒ Object


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

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