Class: C0::Unit
- Inherits:
-
Object
- Object
- C0::Unit
- Defined in:
- lib/c0/body.rb
Overview
One unit as written: its raw value bytes (layout included) and its
sub-units (␞a␟b␚␟c: b holds the sub-unit c), each a Unit with
sub-units of its own (␞a␚␟b␚␚␟c: a holds b holds c).
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#subs ⇒ Object
readonly
Returns the value of attribute subs.
Class Method Summary collapse
-
.from_tree(buf, tree) ⇒ Object
A unit from the extension's [start, end, subs] tree over
buf.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(raw, subs = []) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
-
#level ⇒ Object
The unit as a nested level (a Body).
- #level? ⇒ Boolean
- #ref? ⇒ Boolean
-
#subs? ⇒ Boolean
Whether the unit holds sub-units.
-
#type ⇒ Object
One of C0::UnitType.
-
#value ⇒ Object
The logical value.
Constructor Details
#initialize(raw, subs = []) ⇒ Unit
Returns a new instance of Unit.
202 203 204 205 |
# File 'lib/c0/body.rb', line 202 def initialize(raw, subs = []) @raw = raw @subs = subs end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
200 201 202 |
# File 'lib/c0/body.rb', line 200 def raw @raw end |
#subs ⇒ Object (readonly)
Returns the value of attribute subs.
200 201 202 |
# File 'lib/c0/body.rb', line 200 def subs @subs end |
Class Method Details
.from_tree(buf, tree) ⇒ Object
A unit from the extension's [start, end, subs] tree over buf.
208 209 210 211 |
# File 'lib/c0/body.rb', line 208 def self.from_tree(buf, tree) s, e, subs = tree new(buf.byteslice(s, e - s), subs.map { |t| from_tree(buf, t) }) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
233 |
# File 'lib/c0/body.rb', line 233 def ==(other) = other.is_a?(Unit) && other.raw == @raw && other.subs == @subs |
#hash ⇒ Object
237 |
# File 'lib/c0/body.rb', line 237 def hash = [@raw, @subs].hash |
#inspect ⇒ Object
239 |
# File 'lib/c0/body.rb', line 239 def inspect = "#<C0::Unit #{@raw.inspect}#{@subs.empty? ? '' : " subs=#{@subs.inspect}"}>" |
#level ⇒ Object
The unit as a nested level (a Body). Raises C0::Error when it is not one.
227 228 229 230 231 |
# File 'lib/c0/body.rb', line 227 def level b = C0.to_bin(@raw) ls, le = Ext.unit_level(b, 0, b.bytesize) Body.view(b, ls, le) end |
#subs? ⇒ Boolean
Whether the unit holds sub-units.
224 |
# File 'lib/c0/body.rb', line 224 def subs? = !@subs.empty? |
#type ⇒ Object
One of C0::UnitType.
217 |
# File 'lib/c0/body.rb', line 217 def type = Ext.unit_type(@raw, 0, @raw.bytesize) |