Class: Hermeneutics::MBox::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/hermeneutics/boxes.rb

Overview

:stopdoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, start, stop) ⇒ Region

Returns a new instance of Region.



131
132
133
134
# File 'lib/hermeneutics/boxes.rb', line 131

def initialize file, start, stop
  @file, @start, @stop = file, start, stop
  rewind
end

Class Method Details

.open(file, start, stop) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/hermeneutics/boxes.rb', line 121

def open file, start, stop
  t = file.tell
  begin
    i = new file, start, stop
    yield i
  ensure
    file.seek t
  end
end

Instance Method Details

#each_lineObject Also known as: eat_lines



145
146
147
148
149
150
# File 'lib/hermeneutics/boxes.rb', line 145

def each_line
  @file.each_line { |l|
    break if @file.tell > @stop
    yield l
  }
end

#read(n = nil) ⇒ Object



136
137
138
139
140
# File 'lib/hermeneutics/boxes.rb', line 136

def read n = nil
  m = @stop - @file.tell
  n = m if not n or n > m
  @file.read n
end

#rewindObject



135
# File 'lib/hermeneutics/boxes.rb', line 135

def rewind ; @file.seek @start ; end

#to_sObject



141
142
143
144
# File 'lib/hermeneutics/boxes.rb', line 141

def to_s
  rewind
  read
end