Class: Zeiger::FileInfo
- Inherits:
-
Object
- Object
- Zeiger::FileInfo
- Defined in:
- lib/zeiger/file_info.rb
Instance Attribute Summary collapse
-
#comment_regexes ⇒ Object
Returns the value of attribute comment_regexes.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#index ⇒ Object
Returns the value of attribute index.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#nc_nb_line_count ⇒ Object
Returns the value of attribute nc_nb_line_count.
-
#ngrams ⇒ Object
Returns the value of attribute ngrams.
-
#stats_group ⇒ Object
Returns the value of attribute stats_group.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #add_ngram(ngram) ⇒ Object
-
#initialize(index, filename, stats) ⇒ FileInfo
constructor
A new instance of FileInfo.
- #local_filename ⇒ Object
- #match(regex) ⇒ Object
- #summary ⇒ Object
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_regexes ⇒ Object
Returns the value of attribute comment_regexes.
5 6 7 |
# File 'lib/zeiger/file_info.rb', line 5 def comment_regexes @comment_regexes end |
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/zeiger/file_info.rb', line 5 def filename @filename end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/zeiger/file_info.rb', line 5 def index @index end |
#lines ⇒ Object
Returns the value of attribute lines.
5 6 7 |
# File 'lib/zeiger/file_info.rb', line 5 def lines @lines end |
#nc_nb_line_count ⇒ Object
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 |
#ngrams ⇒ Object
Returns the value of attribute ngrams.
5 6 7 |
# File 'lib/zeiger/file_info.rb', line 5 def ngrams @ngrams end |
#stats_group ⇒ Object
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_filename ⇒ Object
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 |
#summary ⇒ Object
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 |