Class: Codescout::FileStats

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

Constant Summary collapse

PATTERNS =
{
  line_comment:        /^\s*#/,
  begin_block_comment: /^=begin/,
  end_block_comment:   /^=end/,
  class:               /^\s*class\s+[_A-Z]/,
  method:              /^\s*def\s+[_a-z]/,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path, path) ⇒ FileStats

Returns a new instance of FileStats.



18
19
20
21
22
23
24
25
# File 'lib/codescout/file_stats.rb', line 18

def initialize(base_path, path)
  @path      = path
  @full_path = File.join(base_path, path)

  init_metrics
  calculate_file_metrics
  calculate_code_metrics
end

Instance Attribute Details

#classes_countObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def classes_count
  @classes_count
end

#file_sizeObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def file_size
  @file_size
end

#linesObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def lines
  @lines
end

#locObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def loc
  @loc
end

#method_locObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def method_loc
  @method_loc
end

#methods_countObject (readonly)

File size in bytes



11
12
13
# File 'lib/codescout/file_stats.rb', line 11

def methods_count
  @methods_count
end

Instance Method Details

#to_hashObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/codescout/file_stats.rb', line 27

def to_hash
  {
    file_size:     file_size,
    lines:         lines,
    loc:           loc,
    method_loc:    method_loc,
    classes_count: classes_count,
    methods_count: methods_count
  }
end