Class: CodeStats::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Report

Returns a new instance of Report.



3
4
5
6
# File 'lib/code_stats/report.rb', line 3

def initialize *args
  @filters = args.extract_options!
  @projects = args
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



2
3
4
# File 'lib/code_stats/report.rb', line 2

def filters
  @filters
end

#projectsObject (readonly)

Returns the value of attribute projects.



2
3
4
# File 'lib/code_stats/report.rb', line 2

def projects
  @projects
end

Instance Method Details

#renderObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/code_stats/report.rb', line 8

def render
  # preparing data
  data = projects.clone
  data.sort!{|a, b| b.characters_count(filters) <=> a.characters_count(filters)}
  data.collect! do |p|
    o = OpenObject.new
    o.name = p.name

    o.characters_count = p.characters_count(filters)
    o.characters_count_by_language = p.characters_count_by_language(filters)
    o.ignored_characters_count_by_language = p.characters_count_by_language.reject do |lang, count|
      o.characters_count_by_language.include?(lang)
    end

    o.specs = OpenObject.new
    o.specs.characters_count = p.specs.characters_count(filters)
    o.specs.characters_count_by_language = p.specs.characters_count_by_language(filters)
    o.specs.ignored_characters_count_by_language = p.specs.characters_count_by_language.reject do |lang, count|
      o.specs.characters_count_by_language.include?(lang)
    end

    o.unknown_extensions = p.unknown_extensions

    o
  end

  # rendering
  dir = __FILE__.dirname.to_dir
  css = [dir['report/style.css'].read].join("\n")
  js = %w(jquery.js highchart.js report.js).collect{|n| dir["report/#{n}"].read}.join("\n")

  report = dir / 'report.html.haml'
  report.render(projects: data, filters: filters, css: css, js: js)
end