Sha256: 8b96add9dc07f7874901ee8f2239811c077e9097cb5baa7b630cae4bf6122575
Contents?: true
Size: 1.46 KB
Versions: 116
Compression:
Stored size: 1.46 KB
Contents
# # module Statistics # # class Count # # def initialize *patterns @patterns = patterns @count = 0 end # Calculate the value starting from the given byte offset. # def from filename, options = {} @patterns.inject(0) do |total, pattern| total + count(pattern, filename, options) end end # Calculate and reset the value starting from the given byte offset. # def reset_from filename, options = {} @count = from filename, options end # Calculate and add the value starting from the given byte offset. # def add_from filename, options = {} @count += from filename, options end # Count the pattern. # def count pattern, filename, options = {} extended = options[:extended] ? '-E' : '-G' nonmatching = options[:nonmatching] ? '-v' : '' count_lines "#{extended} #{nonmatching} -i -s -e \"#{pattern}\"", filename end # Count the amount of lines the pattern matches. # def count_lines extended_pattern, filename # puts "grep -c #{extended_pattern} #{filename}" sys_i "grep -c #{extended_pattern} #{filename}" end # Convert the system's response into an integer. # def sys_i text sys(text).to_i end # Run the text on the system. # def sys text `#{text}`.chomp end def to_s @count.to_s end end end
Version data entries
116 entries across 116 versions & 1 rubygems