Class: Rsssf::ScheduleReport

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rsssf/reports/schedule.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



55
56
57
58
# File 'lib/rsssf/reports/schedule.rb', line 55

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

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



53
54
55
# File 'lib/rsssf/reports/schedule.rb', line 53

def title
  @title
end

Class Method Details

.build(files, title:, patch: nil) ⇒ Object

quick hack? pass along (optional) patch



20
21
22
23
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
# File 'lib/rsssf/reports/schedule.rb', line 20

def self.build( files, title:, 
                       patch: nil )
  linter = Parser::Linter.new

  stats = []
  files.each_with_index do |file,i|

    puts "==> [#{i+1}/#{files.size}] reading >#{file}<..."  

    txt = read_text( file )

    if patch && patch.respond_to?(:on_parse)
      season_dir = File.basename(File.dirname(file)) 
      season     = Season( season_dir )
      basename   = File.basename(file, File.extname(file)) 
      puts "  [debug] before  patch.on_parse #{basename}, #{season}"
      txt = patch.on_parse( txt, basename, season )
    end
  
    linter.parse( txt, parse: true,
                       path:  file  )   ## todo/fix - change path to file/filename - why? why not?
    
    stat = ScheduleStat.new
    stat.path   = file
    stat.errors = linter.errors
     
    stats << stat
  end

  new( stats, title: title )
end

Instance Method Details

#build_summaryObject



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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rsssf/reports/schedule.rb', line 64

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 ="\n# \#{title}\n\nfootball.db RSSSF (Rec.Sport.Soccer Statistics Foundation) Archive Data for\n\#{title}\n\n"

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


=begin
  footer =<<EOS

## Questions? Comments?

Send them along to the
[Open Sports & Friends Forum](http://groups.google.com/group/opensport).
Thanks!
EOS
=end



  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 "        txt << \"     in line >\#{line}<\\n\"    unless line.empty?\n     end\n     txt << \"```\\n\"\n   end\n\n=begin\n  stats.each do |stat|\n    txt << \"| \#{stat.season} \"\n    txt << \"| [\#{stat.filename}](\#{stat.path}/\#{stat.filename}) \"\n    txt << \"| \#{stat.rounds} \"\n    txt << \"|\\n\"\n  end\n=end\n\n \n  ## txt << footer\n  txt\nend\n"

#save(path) ⇒ Object

save report as README.md in repo



61
# File 'lib/rsssf/reports/schedule.rb', line 61

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