Class: Hash

Inherits:
Object show all
Defined in:
lib/cbor-pure.rb,
lib/cbor-diagnostic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cbor_entriesObject

Returns the value of attribute cbor_entries.



39
40
41
# File 'lib/cbor-pure.rb', line 39

def cbor_entries
  @cbor_entries
end

Class Method Details

.cbor_from_entries(entries) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/cbor-pure.rb', line 40

def self.cbor_from_entries(entries)
  h = Hash[entries]
  if h.size != entries.size   # dupkeys found
    h.cbor_entries = entries
  end
  h
end

Instance Method Details

#cbor_diagnostic(options = {}) ⇒ Object



111
112
113
# File 'lib/cbor-diagnostic.rb', line 111

def cbor_diagnostic(options = {})
  "{#{"_ " if cbor_stream?}#{map{ |k, v| %{#{k.cbor_diagnostic(options)}: #{v.cbor_diagnostic(options)}}}.join(", ")}#{cbor_map_lost_warning}}"
end

#cbor_map_lost_warningObject



55
56
57
58
59
60
# File 'lib/cbor-pure.rb', line 55

def cbor_map_lost_warning
  if cbor_entries
    lost = cbor_entries.size - size
    " / #{lost} DUP KEY#{"S" if lost > 1} LOST / "
  end
end

#cbor_map_push(key, value, entries) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/cbor-pure.rb', line 47

def cbor_map_push(key, value, entries)
  entries << [key, value]
  n = size
  self[key] = value
  if n == size # key was overwritten
    self.cbor_entries = entries
  end
end