Class: CodeStats::Stats
- Inherits:
-
Object
- Object
- CodeStats::Stats
- Defined in:
- lib/code_stats.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#empty ⇒ Object
Returns the value of attribute empty.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#lines ⇒ Object
Returns the value of attribute lines.
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(file) ⇒ Stats
constructor
A new instance of Stats.
Constructor Details
#initialize(file) ⇒ Stats
Returns a new instance of Stats.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code_stats.rb', line 12 def initialize(file) @file = file @lines, @comments, @empty = 0, 0, 0 File.open(file).each_line do |line| @lines += 1 case line when /^\s*$/ @empty += 1 when /^\s*#/ @comments += 1 end end end |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
10 11 12 |
# File 'lib/code_stats.rb', line 10 def comments @comments end |
#empty ⇒ Object
Returns the value of attribute empty.
10 11 12 |
# File 'lib/code_stats.rb', line 10 def empty @empty end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/code_stats.rb', line 9 def file @file end |
#lines ⇒ Object
Returns the value of attribute lines.
10 11 12 |
# File 'lib/code_stats.rb', line 10 def lines @lines end |
Instance Method Details
#code ⇒ Object
28 29 30 |
# File 'lib/code_stats.rb', line 28 def code lines - comments - empty end |