Class: Bytemapper::Table

Inherits:
Array
  • Object
show all
Includes:
Flattenable, Nameable
Defined in:
lib/bytemapper/table.rb

Instance Attribute Summary collapse

Attributes included from Nameable

#name, #names

Instance Method Summary collapse

Methods included from Flattenable

#flatten

Constructor Details

#initialize(shape, rows = nil) ⇒ Table

Returns a new instance of Table.



9
10
11
12
# File 'lib/bytemapper/table.rb', line 9

def initialize(shape, rows = nil)
  @bytes = nil
  @shape = Bytemapper.get(shape)
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



7
8
9
# File 'lib/bytemapper/table.rb', line 7

def bytes
  @bytes
end

#shapeObject (readonly)

Returns the value of attribute shape.



7
8
9
# File 'lib/bytemapper/table.rb', line 7

def shape
  @shape
end

Instance Method Details

#populate(bytes) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bytemapper/table.rb', line 14

def populate(bytes)
  @bytes = StringIO.from(bytes)

  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

#sizeObject



27
28
29
# File 'lib/bytemapper/table.rb', line 27

def size
  empty? ? 0 : map(&:size).reduce(:+)
end