Class: Bytemapper::Table
- Inherits:
-
Array
- Object
- Array
- Bytemapper::Table
- Includes:
- Flattenable, Nameable
- Defined in:
- lib/bytemapper/table.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
Attributes included from Nameable
Instance Method Summary collapse
-
#initialize(shape, rows = nil) ⇒ Table
constructor
A new instance of Table.
- #populate(bytes) ⇒ Object
- #size ⇒ Object
Methods included from Flattenable
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
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
7 8 9 |
# File 'lib/bytemapper/table.rb', line 7 def bytes @bytes end |
#shape ⇒ Object (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 |
#size ⇒ Object
27 28 29 |
# File 'lib/bytemapper/table.rb', line 27 def size empty? ? 0 : map(&:size).reduce(:+) end |