Class: C0::FileView

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

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

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


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)