Class: C0::FileView
Overview
A file within a body: its name and groups. The file before the first FS
is the unnamed leading? file. Enumerates the groups.
Instance Attribute Summary collapse
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
Instance Method Summary collapse
- #each ⇒ Object
-
#group(name) ⇒ Object
(also: #[])
The first group with this name.
- #groups ⇒ Object
-
#initialize(buf, name_start, name_end, start, stop, leading = false) ⇒ FileView
constructor
A new instance of FileView.
-
#leading? ⇒ Boolean
Whether this is the unnamed file before the first FS.
- #name ⇒ Object
- #raw ⇒ Object
Constructor Details
#initialize(buf, name_start, name_end, start, stop, leading = false) ⇒ FileView
Returns a new instance of FileView.
97 98 99 100 101 102 103 104 |
# File 'lib/c0/body.rb', line 97 def initialize(buf, name_start, name_end, start, stop, leading = false) @buf = buf @name_start = name_start @name_end = name_end @start = start @stop = stop @leading = leading end |
Instance Attribute Details
#start ⇒ Object (readonly)
Returns the value of attribute start.
95 96 97 |
# File 'lib/c0/body.rb', line 95 def start @start end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop.
95 96 97 |
# File 'lib/c0/body.rb', line 95 def stop @stop end |
Instance Method Details
#each ⇒ Object
123 |
# File 'lib/c0/body.rb', line 123 def each(&) = groups.each(&) |
#group(name) ⇒ Object Also known as: []
The first group with this name. Raises C0::KeyError when there is none.
116 117 118 119 |
# File 'lib/c0/body.rb', line 116 def group(name) needle = C0.to_bin(name) groups.find { |g| g.name == needle } or raise KeyError, "No group named '#{name}'" end |
#groups ⇒ Object
111 112 113 |
# File 'lib/c0/body.rb', line 111 def groups @groups ||= Ext.groups(@buf, @start, @stop).map { |d, ns, ne, s, e| Group.new(@buf, d, ns, ne, s, e) } end |
#leading? ⇒ Boolean
Whether this is the unnamed file before the first FS.
109 |
# File 'lib/c0/body.rb', line 109 def leading? = @leading |
#name ⇒ Object
106 |
# File 'lib/c0/body.rb', line 106 def name = @buf.byteslice(@name_start, @name_end - @name_start) |
#raw ⇒ Object
125 |
# File 'lib/c0/body.rb', line 125 def raw = @buf.byteslice(@start, @stop - @start) |