Class: Rsssf::PageReport

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats, title:) ⇒ PageReport

Returns a new instance of PageReport.



21
22
23
24
# File 'lib/rsssf/reports/page.rb', line 21

def initialize( stats, title: )
  @stats = stats
  @title = title
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.build(files, title:) ⇒ Object



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

def self.build( files, title:  )   
  stats = []
  files.each do |file|
    page = Page.read_txt( file )
    stats << page.build_stat
  end

  new( stats, title: title )
end

Instance Method Details

#build_summaryObject



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
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rsssf/reports/page.rb', line 30

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}

EOS

## no longer add last update
##  _Last Update: #{Time.now}_


  txt = ''
  txt << header

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

## note - removed season (no longer tracked here)

  stats.each do |stat|
    ## get basename from source url
    url_path  = URI.parse( stat.source ).path
    basename  = File.basename( url_path, File.extname( url_path ) )  ## e.g. duit92.txt or duit92.html => duit92
  
    txt << "| [#{basename}.txt](#{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

save report as README.md in repo



27
# File 'lib/rsssf/reports/page.rb', line 27

def save( path ) write_text( path, build_summary ); end