class Pnjson::Chunk

Constants

ANCILLARY_CHUNKS_TYPES
CRITICAL_CHUNKS_TYPES

Attributes

crc[RW]
data[RW]
length[RW]
type[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/pnjson/chunk.rb, line 13
def initialize(options = {})
  @length = options[:length]
  @type   = hex_to_ascii(options[:type])
  @data   = options[:data]
  @crc    = options[:crc]
end

Public Instance Methods

to_hash() click to toggle source
# File lib/pnjson/chunk.rb, line 20
def to_hash
  {
    length: @length,
    type: @type,
    data: @data,
    crc: @crc
  }
end

Private Instance Methods

hex_to_ascii(str) click to toggle source
# File lib/pnjson/chunk.rb, line 30
def hex_to_ascii(str)
  str.scan(/../).map { |x| x.hex.chr }.join
end