Class: Rsssf::PageReport

Inherits:
Object
  • Object
show all
Defined in:
lib/rsssf/reports/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats, opts) ⇒ PageReport

Returns a new instance of PageReport.



10
11
12
13
14
15
# File 'lib/rsssf/reports/page.rb', line 10

def initialize( stats, opts )
  @stats = stats
  @opts  = opts
    
  @title = opts[:title] || 'Your Title Here' 
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/rsssf/reports/page.rb', line 8

def title
  @title
end

Instance Method Details

#build_summaryObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rsssf/reports/page.rb', line 24

def build_summary

  stats = @stats.sort do |l,r|
    r.year <=> l.year
  end

  header =<<EOS

# #{title}

football.db RSSSF Archive Data Summary for #{title}

_Last Update: #{Time.now}_

EOS

  txt = ''
  txt << header

  txt << "| Season | File   | Authors  | Last Updated | Lines (Chars) | Sections |\n"
  txt << "| :----- | :----- | :------- | :----------- | ------------: | :------- |\n"

  stats.each do |stat|
    txt << "| #{stat.season} "
    txt << "| [#{stat.basename}.txt](#{stat.basename}.txt) "
    txt << "| #{stat.authors} "
    txt << "| #{stat.last_updated} "
    txt << "| #{stat.line_count} (#{stat.char_count}) "
    txt << "| #{stat.sections.join(', ')} "
    txt << "|\n"
  end

  txt << "\n\n" 
  txt
end

#save(path) ⇒ Object



17
18
19
20
21
22
# File 'lib/rsssf/reports/page.rb', line 17

def save( path )
  ### save report as README.md in repo
  File.open( path, 'w' ) do |f|
    f.write build_summary
  end
end