Class: C0::Table

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/c0.rb

Overview

A tabular group: name, headers, and records.

Instance Method Summary collapse

Constructor Details

#initialize(buf, offset = 0) ⇒ Table

Returns a new instance of Table.



133
134
135
136
137
# File 'lib/c0.rb', line 133

def initialize(buf, offset = 0)
  @buf = C0.to_bin(buf)
  ns, ne, @headers, @records = Ext.table(@buf, offset)
  @name = [ns, ne]
end

Instance Method Details

#each ⇒ Object



156
157
158
159
160
# File 'lib/c0.rb', line 156

def each
  return enum_for(:each) unless block_given?

  @records.each { |s, e| yield Record.new(@buf, s, e) }
end

#header_count ⇒ Object



143
# File 'lib/c0.rb', line 143

def header_count = @headers.size

#headers ⇒ Object



141
# File 'lib/c0.rb', line 141

def headers = @headers.map { |s, e| @buf.byteslice(s, e - s) }

#name ⇒ Object



139
# File 'lib/c0.rb', line 139

def name = @buf.byteslice(@name[0], @name[1] - @name[0])

#record(index) ⇒ Object



147
148
149
150
# File 'lib/c0.rb', line 147

def record(index)
  s, e = @records[index]
  Record.new(@buf, s, e)
end

#record_count ⇒ Object



145
# File 'lib/c0.rb', line 145

def record_count = @records.size

#records ⇒ Object



152
# File 'lib/c0.rb', line 152

def records = (0...@records.size).map { |i| record(i) }

#size ⇒ Object



154
# File 'lib/c0.rb', line 154

def size = @records.size