Class: Rsssf::Project

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

Constant Summary

Constants included from Utils

Utils::YEAR_FROM_NAME_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#archive_dir_for_season, #year_from_file, #year_from_name

Constructor Details

#initialize(dir, title: 'Your Title Here', slug: nil) ⇒ Project

Returns a new instance of Project.



13
14
15
16
17
18
19
# File 'lib/rsssf/project.rb', line 13

def initialize( dir,
                title: 'Your Title Here',
                slug:  nil )
  @root_dir  = dir
  @title     = title
  @slug      = slug     ## note - might be a proc e.g.  ->(season) {}
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



10
11
12
# File 'lib/rsssf/project.rb', line 10

def root_dir
  @root_dir
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/rsssf/project.rb', line 10

def title
  @title
end

Instance Method Details

#_find_pagesObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/rsssf/project.rb', line 26

def _find_pages
  glob = "#{pages_dir}/**/*.txt"
  print "  glob >#{glob}<..."

  files = Dir.glob( glob )
  puts "  #{files.size} page(s) .txt found"

  ## pp files
  files
end

#_mk_basename(season) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/rsssf/project.rb', line 123

def _mk_basename( season )
   slug =  @slug.is_a?(Proc) ? @slug.call( season ) : @slug

   ## e.g.  braz01, braz09 or braz2010
   basename = "#{slug}#{_mk_year(season)}"
   basename
end

#_mk_year(season) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rsssf/project.rb', line 131

def _mk_year( season )
##
##   note -  00, 01, 02, 03, 04, 05, 06, 07, 08, 09  => 2000, 2001, .. 2009
##           10, 11, 12, .. 99                       => 1910 !!, 1911, 1912, .. 1999
##
##            2010, 2011, 2012, ...
##
##    fix - check for 18xx ???  requires full year!!!
##     only 1910 to 2009  (10..09)

    slug =  if season.end_year >= 1910 &&
               season.end_year <  2010
                 ## cut off all digits (only keep last two)s
                 ##  convert end_year to string with leading zero
                 ## e.g. 00 / 01 / 99 / 98 / 11 / etc.
                 '%02d' % (season.end_year % 100)
              else
                 '%4d' % season.end_year
              end
    slug
end

#each_page(seasons, &blk) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/rsssf/project.rb', line 109

def each_page( seasons, &blk )
   seasons.each do |season|
      season = Season( season )
      basename = _mk_basename( season )

      path = "#{pages_dir}/#{basename}.txt"
      page = Page.read_txt( path )

      blk.call( season, page )
   end
end

#make_pages_summaryObject



39
40
41
42
43
44
45
46
47
# File 'lib/rsssf/project.rb', line 39

def make_pages_summary

  files = _find_pages()

  report = PageReport.build( files, title: @title )    ## pass in title etc.

  ### save report as README.md in pages/ dir in project root_dir
  report.save( "#{pages_dir}/README.md" )
end

#make_schedules(txt, archive: false) ⇒ Object



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
# File 'lib/rsssf/project.rb', line 66

def make_schedules( txt, archive: false )
   configs = parse_schedules( txt )
   ## pp configs

   configs.each do |config|
     header       = config['header']
     seasons      = config['seasons']
     basename     = config['basename'] || config['slug']
     title_tmpl   = config['title']


     ## note: header allows hierarchy e.g.  (see england and others)
     ##   Cup Tournaments › FA Cup  or
     ##   Cup Tournaments > FA Cup
     header_hiera = header.split( /[ ]* [›>] [ ]*/x )


     puts "==> #{header_hiera.join('')} - #{seasons.size} season(s)..."

     i=0
     each_page( seasons ) do |season, page|
       title = title_tmpl.sub( '{season}', season.to_s )
        puts "  [#{i+1}/#{seasons.size}] #{season} => #{basename}, #{title}..."

       sched = page.find_schedule!( header: header_hiera )


        outpath =   if archive
                       ## use archive/1990s and such if season <= 2009/10
                       "#{root_dir}/#{archive_dir_for_season(season)}/#{basename}.txt"
                    else
                       "#{root_dir}/#{season.to_path}/#{basename}.txt"
                    end
       sched.save( outpath, header: "= #{title}\n\n" )
        i+=1
     end
  end
end

#make_schedules_summaryObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rsssf/project.rb', line 51

def make_schedules_summary
   ## find all match datafiles
   ##    note - looks for season pattern for now
   ##                 YYYY-YY or YYYY
   glob = "#{root_dir}/**/{[12][0-9][0-9][0-9]-[0-9][0-9],[12][0-9][0-9][0-9]}/*.txt"
   print "  glob >#{glob}<..."
   files = Dir.glob( glob )
   puts "  #{files.size} datatfile(s) .txt found"
   pp files

   report = ScheduleReport.build( files, title: @title )   ## pass in title etc.
   report.save( "#{root_dir}/README.md" )
end

#pages_dirObject



22
# File 'lib/rsssf/project.rb', line 22

def pages_dir()  "#{root_dir}/pages"; end