Class: Puppet::Pops::PN::Map

Inherits:
Object
  • Object
show all
Includes:
Puppet::Pops::PN
Defined in:
lib/puppet/pops/pn.rb

Constant Summary

Constants included from Puppet::Pops::PN

KEY_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Puppet::Pops::PN

#==, #as_call, #as_parameters, #double_quote, #format_elements, #pnError, #to_s, #with_name

Constructor Details

#initialize(entries) ⇒ Map

Returns a new instance of Map.



204
205
206
207
# File 'lib/puppet/pops/pn.rb', line 204

def initialize(entries)
  entries.each { |e| pnError("key #{e.key} does not conform to pattern /#{KEY_PATTERN.source}/)") unless e.key =~ KEY_PATTERN }
  @entries = entries
end

Instance Attribute Details

#entriesObject (readonly)



202
203
204
# File 'lib/puppet/pops/pn.rb', line 202

def entries
  @entries
end

Instance Method Details

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/puppet/pops/pn.rb', line 209

def eql?(o)
  o.is_a?(Map) && @entries == o.entries
end

#format(indent, b) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/puppet/pops/pn.rb', line 213

def format(indent, b)
  local_indent = indent ? indent.increase : nil
  b << '{'
  @entries.each_with_index do |e, i|
    if indent
      b << "\n" << local_indent.current
    elsif i > 0
      b << ' '
    end
    b << ':' << e.key
    b << ' '
    e.value.format(local_indent, b)
  end
  b << '}'
end

#to_dataObject



229
230
231
232
233
# File 'lib/puppet/pops/pn.rb', line 229

def to_data
  r = []
  @entries.each { |e| r << e.key << e.value.to_data }
  { '#' => r }
end