Class: Glark::File

Inherits:
Object
  • Object
show all
Defined in:
lib/glark/io/file/file.rb

Overview

A thing that can be grepped (er, glarked).

Direct Known Subclasses

BinaryFile, GzFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname, io, range) ⇒ File

Returns a new instance of File.



12
13
14
15
16
17
18
# File 'lib/glark/io/file/file.rb', line 12

def initialize fname, io, range
  @fname = fname
  @range = range

  linescls = $/ == "\n" ? Glark::IO::LinesCR : Glark::IO::LinesNonCR
  @lines = linescls.new fname, io
end

Instance Attribute Details

#fnameObject (readonly)

Returns the value of attribute fname.



10
11
12
# File 'lib/glark/io/file/file.rb', line 10

def fname
  @fname
end

Instance Method Details

#each_line(&blk) ⇒ Object



24
25
26
# File 'lib/glark/io/file/file.rb', line 24

def each_line &blk
  @lines.each_line(&blk)
end

#get_line(lnum) ⇒ Object

Returns the given line for this file. For this method, a line ends with a CR, as opposed to the “lines” method, which ends with $/.



35
36
37
# File 'lib/glark/io/file/file.rb', line 35

def get_line lnum
  @lines.get_line lnum
end

#get_linesObject

Returns the lines for this file, separated by end of line sequences.



29
30
31
# File 'lib/glark/io/file/file.rb', line 29

def get_lines
  @lines.get_lines
end

#get_range_endObject



48
49
50
# File 'lib/glark/io/file/file.rb', line 48

def get_range_end
  @range && @range.to && @range.to_line(@range.to, linecount)
end

#get_range_startObject



44
45
46
# File 'lib/glark/io/file/file.rb', line 44

def get_range_start
  @range && @range.from && @range.to_line(@range.from, linecount)
end

#get_region(rnum) ⇒ Object

Returns the region/range that is represented by the region number.



40
41
42
# File 'lib/glark/io/file/file.rb', line 40

def get_region rnum
  @lines.get_region rnum
end

#linecountObject



20
21
22
# File 'lib/glark/io/file/file.rb', line 20

def linecount
  @lines.count
end

#search(expr, output) ⇒ Object



52
53
54
55
# File 'lib/glark/io/file/file.rb', line 52

def search expr, output
  expr.process self, output
  output.matched?
end