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


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

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)


198
199
200
# File 'lib/puppet/pops/pn.rb', line 198

def entries
  @entries
end

Instance Method Details

#eql?(o) ⇒ Boolean


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

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

#format(indent, b) ⇒ Object


209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/puppet/pops/pn.rb', line 209

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


225
226
227
228
229
# File 'lib/puppet/pops/pn.rb', line 225

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