module CBOR::PP::PPMethods

Public Instance Methods

comma_breakable() click to toggle source

XXX: a nested group that is broken should not have things added at the end

# File lib/cbor-pp.rb, line 29
def comma_breakable
  text ','
  fill_breakable
end
pp(obj) click to toggle source

Adds obj to the pretty printing buffer using Object#cbor_pp.

# File lib/cbor-pp.rb, line 24
def pp(obj)
  group {obj.cbor_pp self}
end
pp_hash(obj, anno) click to toggle source

A pretty print for a Hash

# File lib/cbor-pp.rb, line 48
def pp_hash(obj, anno)
  s = "#{anno}{"
  group(1, s, '}') {
    seplist(obj, nil, :each_pair) {|k, v|
      group {
        pp k
        text ':'
        group(1) {
          breakable ' '
          pp v
        }
      }
    }
  }
end
seplist(list, sep=nil, iter_method=:each) { |element| ... } click to toggle source
# File lib/cbor-pp.rb, line 34
def seplist(list, sep=nil, iter_method=:each) # :yield: element
  sep ||= lambda { comma_breakable }
  first = true
  list.__send__(iter_method) {|*v|
    if first
      first = false
    else
      sep.call
    end
    yield(*v)
  }
end