Class: Loco::Stats
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #blank?(str) ⇒ Boolean
- #count_lines(path) ⇒ Object
-
#initialize(path) ⇒ Stats
constructor
A new instance of Stats.
- #matches(options) ⇒ Object
- #to_s ⇒ Object
Methods included from Util
Constructor Details
#initialize(path) ⇒ Stats
Returns a new instance of Stats.
9 10 11 12 |
# File 'lib/loco/stats.rb', line 9 def initialize(path) @path = path @lines = count_lines(path) end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
7 8 9 |
# File 'lib/loco/stats.rb', line 7 def lines @lines end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/loco/stats.rb', line 7 def path @path end |
Instance Method Details
#blank?(str) ⇒ Boolean
14 15 16 |
# File 'lib/loco/stats.rb', line 14 def blank? str str.nil? || str.strip == "" end |
#count_lines(path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/loco/stats.rb', line 18 def count_lines path File.read(path).split(/\n/).inject(0) {|sum, line| sum + (blank?(line) ? 0 : 1) } rescue Exception => e puts "ERROR: reading #{path}: #{e.}" puts "" puts "consider adding this line to your .loco:" puts "" puts "Loco::Counter::EXCLUDE << /^#{path.gsub /\//, "\\/"}/" puts "" 0 end |
#matches(options) ⇒ Object
34 35 36 |
# File 'lib/loco/stats.rb', line 34 def matches [:size].nil? || ([:size] == lines) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/loco/stats.rb', line 30 def to_s "#{align lines} #{path}" end |