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



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

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

#as_call(name) ⇒ Object



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

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

#as_parametersObject



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

def as_parameters
  [self]
end

#double_quote(str, bld) ⇒ Object



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

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



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

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)


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

def pnError(message)
  raise ArgumentError, message
end

#to_sObject



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

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

#with_name(name) ⇒ Object



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

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