class Bytemapper::Table

Attributes

bytes[R]
rows[R]
shape[R]

Public Class Methods

new(shape, rows = nil) click to toggle source
# File lib/bytemapper/table.rb, line 16
def initialize(shape, rows = nil)
  @shape = Bytemapper.get(shape) || shape
  rows.times { self << @shape  }
end

Public Instance Methods

populate(bytes) click to toggle source
# File lib/bytemapper/table.rb, line 21
def populate(bytes)
  bytes = bytes.nil? ? '' : bytes
  @bytes = bytes.is_a?(StringIO) ? bytes : StringIO.new(bytes)
  @bytes.string.force_encoding(Encoding::ASCII_8BIT)
  @shape = Bytemapper.get(shape).nil? ? Bytemapper.get2(shape) : Bytemapper.get(shape)

  (bytes.size / shape.size).times { self << @shape } if unbounded?

  table = Table.new(shape) 
  table.clear
  (bytes.size / shape.size).times do
    table << Chunk.new(@bytes.read(shape.size), shape, shape.name) 
  end
  table
end
size() click to toggle source
# File lib/bytemapper/table.rb, line 41
def size
  empty? ? 0 : map(&:size).reduce(:+)
end
unbounded?() click to toggle source
# File lib/bytemapper/table.rb, line 37
def unbounded?
  empty?
end