Class: CodeStats::Stats

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commentsObject

Returns the value of attribute comments.



10
11
12
# File 'lib/code_stats.rb', line 10

def comments
  @comments
end

#emptyObject

Returns the value of attribute empty.



10
11
12
# File 'lib/code_stats.rb', line 10

def empty
  @empty
end

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/code_stats.rb', line 9

def file
  @file
end

#linesObject

Returns the value of attribute lines.



10
11
12
# File 'lib/code_stats.rb', line 10

def lines
  @lines
end

Instance Method Details

#codeObject



28
29
30
# File 'lib/code_stats.rb', line 28

def code
  lines - comments - empty
end