Class: Rsssf::ScheduleReport
- Inherits:
-
Object
- Object
- Rsssf::ScheduleReport
- Includes:
- Utils
- Defined in:
- lib/rsssf/reports/schedule.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #build_summary ⇒ Object
-
#initialize(stats, title:) ⇒ ScheduleReport
constructor
A new instance of ScheduleReport.
-
#save(path) ⇒ Object
save report as README.md in repo.
Methods included from Utils
#archive_dir_for_season, #year_from_file, #year_from_name
Constructor Details
#initialize(stats, title:) ⇒ ScheduleReport
Returns a new instance of ScheduleReport.
44 45 46 47 |
# File 'lib/rsssf/reports/schedule.rb', line 44 def initialize( stats, title: ) @stats = stats @title = title end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
42 43 44 |
# File 'lib/rsssf/reports/schedule.rb', line 42 def title @title end |
Class Method Details
.build(files, title:, patch: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rsssf/reports/schedule.rb', line 21 def self.build( files, title:, patch: nil ) stats = [] files.each_with_index do |file,i| puts "==> [#{i+1}/#{files.size}] reading >#{file}<..." txt = read_text( file ) stat = ScheduleStat.new stat.path = file stat.errors = [] stats << stat end new( stats, title: title ) end |
Instance Method Details
#build_summary ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rsssf/reports/schedule.rb', line 53 def build_summary ## sort start 1) by season (latest first) than ## 2) by name (e.g. 1-bundesliga, cup, etc.) stats = @stats.sort do |l,r| v = File.basename(File.dirname(r.path)) <=> File.basename(File.dirname(l.path)) v = File.basename(l.path) <=> File.basename(r.path) if v == 0 ## same season v end header =<<TXT # #{title} football.db RSSSF (Rec.Sport.Soccer Statistics Foundation) Archive Data for #{title} TXT errors = [] txt = String.new txt << header txt << "| Season | League, Cup | Errors |\n" txt << "| :----- | :---------- | -----: |\n" stats.each_with_index do |stat,i| path = stat.path season_dir = File.basename(File.dirname( path )) filename = File.basename( path ) ## incl. extension !! season = Season( season_dir ) ## note - use archive_dir_for_season for archive path txt << "| #{season_dir} " txt << "| [#{filename}](#{archive_dir_for_season(season)}/#{filename}) " txt << if stat.errors.size > 0 "| **!! #{stat.errors.size}** " else "| OK " end txt << "|\n" errors += stat.errors if stat.errors.size > 0 end if errors.size > 0 txt << "\n\n" txt << "#{errors.size} errors in #{stats.size} datafile(s)\n\n" txt << "```\n" errors.each do |path, msg, line| season_dir = File.basename(File.dirname( path )) filename = File.basename( path ) ## incl. extension !! txt <<"#{season_dir}/#{filename} -- #{msg}\n" txt << " in line >#{line}<\n" unless line.empty? end txt << "```\n" end txt end |
#save(path) ⇒ Object
save report as README.md in repo
50 |
# File 'lib/rsssf/reports/schedule.rb', line 50 def save( path ) write_text( path, build_summary ); end |