Class: Zeiger::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/zeiger/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, line_number, content) ⇒ Line

Returns a new instance of Line.



6
7
8
9
# File 'lib/zeiger/line.rb', line 6

def initialize file, line_number, content
  @file, @line_number, @content = file, line_number, content
  @hash = "#{file.filename}##{line_number}".hash
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/zeiger/line.rb', line 3

def content
  @content
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/zeiger/line.rb', line 3

def file
  @file
end

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'lib/zeiger/line.rb', line 4

def hash
  @hash
end

#line_numberObject

Returns the value of attribute line_number.



3
4
5
# File 'lib/zeiger/line.rb', line 3

def line_number
  @line_number
end

Instance Method Details

#==(other) ⇒ Object



15
# File 'lib/zeiger/line.rb', line 15

def ==       other  ; self.file == other.file && self.line_number == other.line_number ; end

#matches?(regex) ⇒ Boolean

Returns:

  • (Boolean)


12
# File 'lib/zeiger/line.rb', line 12

def matches? regex  ; content.match regex                                              ; end

#ngram_list(size) ⇒ Object



13
# File 'lib/zeiger/line.rb', line 13

def ngram_list size ; @ngrams ||= content.ngrams(size)                                 ; end

#ngrams(size) ⇒ Object



14
# File 'lib/zeiger/line.rb', line 14

def ngrams    size  ; ngram_list(size).each { |ngram| yield ngram, self }              ; end

#to_sObject



11
# File 'lib/zeiger/line.rb', line 11

def to_s            ; "#{file.local_filename}:#{line_number}:#{content}"               ; end