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.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#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
- #unbounded? ⇒ Boolean
Methods included from Flattenable
Constructor Details
#initialize(shape, rows = nil) ⇒ Table
Returns a new instance of Table.
16 17 18 19 |
# File 'lib/bytemapper/table.rb', line 16 def initialize(shape, rows = nil) @shape = Bytemapper.get(shape) rows.times { self << @shape } end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
13 14 15 |
# File 'lib/bytemapper/table.rb', line 13 def bytes @bytes end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
13 14 15 |
# File 'lib/bytemapper/table.rb', line 13 def rows @rows end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
13 14 15 |
# File 'lib/bytemapper/table.rb', line 13 def shape @shape end |
Instance Method Details
#populate(bytes) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) if unbounded? (bytes.size / shape.size).times { self << @shape } end table = Table.new(shape) table.clear (bytes.size / shape.size).times { table << Chunk.new(@bytes.read(shape.size), shape, shape.name) } table end |
#size ⇒ Object
39 40 41 |
# File 'lib/bytemapper/table.rb', line 39 def size empty? ? 0 : map(&:size).reduce(:+) end |
#unbounded? ⇒ Boolean
35 36 37 |
# File 'lib/bytemapper/table.rb', line 35 def unbounded? empty? end |