Class: Zeiger::FileInfo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, filename, stats) ⇒ FileInfo

Returns a new instance of FileInfo.



7
8
9
10
11
12
# File 'lib/zeiger/file_info.rb', line 7

def initialize index, filename, stats
  @index, @filename, @ngrams, @lines = index, filename, Set.new, []
  @stats_group      = stats.stats_group filename
  @comment_regexes  = stats.comment_rules(filename)
  @nc_nb_line_count = 0
end

Instance Attribute Details

#comment_regexesObject

Returns the value of attribute comment_regexes.



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

def comment_regexes
  @comment_regexes
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#linesObject

Returns the value of attribute lines.



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

def lines
  @lines
end

#nc_nb_line_countObject

Returns the value of attribute nc_nb_line_count.



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

def nc_nb_line_count
  @nc_nb_line_count
end

#ngramsObject

Returns the value of attribute ngrams.



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

def ngrams
  @ngrams
end

#stats_groupObject

Returns the value of attribute stats_group.



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

def stats_group
  @stats_group
end

Instance Method Details

#add_line(line) ⇒ Object



26
27
28
29
# File 'lib/zeiger/file_info.rb', line 26

def add_line line
  lines << line
  @nc_nb_line_count += 1 unless line.blank? || (comment_regexes.any? { |regex| line.matches? regex })
end

#add_ngram(ngram) ⇒ Object



22
23
24
# File 'lib/zeiger/file_info.rb', line 22

def add_ngram ngram
  @ngrams << ngram
end

#local_filenameObject



14
15
16
# File 'lib/zeiger/file_info.rb', line 14

def local_filename
  @_local_filename ||= filename.gsub(/^#{Regexp.escape index.dir}\//, "")
end

#match(regex) ⇒ Object



18
19
20
# File 'lib/zeiger/file_info.rb', line 18

def match regex
  local_filename.match regex
end

#summaryObject



31
32
33
# File 'lib/zeiger/file_info.rb', line 31

def summary
  "[#{index.name}] #{stats_group}\t#{nc_nb_line_count}/#{lines.count}\t: #{local_filename}"
end