Class: C0::Group
Overview
A group: its depth (one plus its SUB prefix: ␝a 1, ␚␝b 2; 0 for the
unnamed leading group), name, optional header row and records. Enumerates
the records.
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
Instance Method Summary collapse
-
#column(name) ⇒ Object
Index of a header name, or nil.
- #each_record ⇒ Object (also: #each)
- #header(index) ⇒ Object
- #header? ⇒ Boolean (also: #has_header?)
- #header_count ⇒ Object
-
#header_row ⇒ Object
The header row as a Record, or nil.
-
#headers ⇒ Object
Header names, or an empty array.
-
#initialize(buf, depth, name_start, name_end, start, stop) ⇒ Group
constructor
A new instance of Group.
- #name ⇒ Object
-
#raw ⇒ Object
The group's contents (after its name).
- #record(index) ⇒ Object
- #record_count ⇒ Object (also: #size)
-
#records ⇒ Object
The live records: header row, notes, commits and dead records skipped.
-
#table ⇒ Object
The group as a table is itself.
Constructor Details
#initialize(buf, depth, name_start, name_end, start, stop) ⇒ Group
Returns a new instance of Group.
136 137 138 139 140 141 142 143 |
# File 'lib/c0/body.rb', line 136 def initialize(buf, depth, name_start, name_end, start, stop) @buf = buf @depth = depth @name_start = name_start @name_end = name_end @start = start @stop = stop end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
134 135 136 |
# File 'lib/c0/body.rb', line 134 def depth @depth end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
134 135 136 |
# File 'lib/c0/body.rb', line 134 def start @start end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop.
134 135 136 |
# File 'lib/c0/body.rb', line 134 def stop @stop end |
Instance Method Details
#column(name) ⇒ Object
Index of a header name, or nil.
167 168 169 170 |
# File 'lib/c0/body.rb', line 167 def column(name) needle = C0.to_bin(name) headers.index(needle) end |
#each_record ⇒ Object Also known as: each
183 |
# File 'lib/c0/body.rb', line 183 def each_record(&) = records.each(&) |
#header(index) ⇒ Object
164 |
# File 'lib/c0/body.rb', line 164 def header(index) = headers[index] |
#header? ⇒ Boolean Also known as: has_header?
155 |
# File 'lib/c0/body.rb', line 155 def header? = !header_row.nil? |
#header_count ⇒ Object
162 |
# File 'lib/c0/body.rb', line 162 def header_count = header_row ? header_row.field_count : 0 |
#header_row ⇒ Object
The header row as a Record, or nil.
148 149 150 151 152 153 |
# File 'lib/c0/body.rb', line 148 def header_row return @header_row if defined?(@header_row) range = Ext.group_header(@buf, @start, @stop) @header_row = range && Record.new(@buf, range[0], range[1]) end |
#headers ⇒ Object
Header names, or an empty array.
160 |
# File 'lib/c0/body.rb', line 160 def headers = header_row ? header_row.values : [] |
#name ⇒ Object
145 |
# File 'lib/c0/body.rb', line 145 def name = @buf.byteslice(@name_start, @name_end - @name_start) |
#raw ⇒ Object
The group's contents (after its name).
191 |
# File 'lib/c0/body.rb', line 191 def raw = @buf.byteslice(@start, @stop - @start) |
#record(index) ⇒ Object
181 |
# File 'lib/c0/body.rb', line 181 def record(index) = records[index] |
#record_count ⇒ Object Also known as: size
177 |
# File 'lib/c0/body.rb', line 177 def record_count = records.size |
#records ⇒ Object
The live records: header row, notes, commits and dead records skipped.
173 174 175 |
# File 'lib/c0/body.rb', line 173 def records @records ||= Ext.group_records(@buf, @start, @stop).map { |s, e| Record.new(@buf, s, e) } end |
#table ⇒ Object
The group as a table is itself.
188 |
# File 'lib/c0/body.rb', line 188 def table = self |