Class: Rsssf::Project
- Inherits:
-
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 end
|
Instance Attribute Details
#root_dir ⇒ Object
Returns the value of attribute root_dir.
10
11
12
|
# File 'lib/rsssf/project.rb', line 10
def root_dir
@root_dir
end
|
#title ⇒ Object
Returns the value of attribute title.
10
11
12
|
# File 'lib/rsssf/project.rb', line 10
def title
@title
end
|
Instance Method Details
#_find_pages ⇒ Object
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"
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
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 )
slug = if season.end_year >= 1910 &&
season.end_year < 2010
'%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_summary ⇒ Object
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 )
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 )
configs.each do |config|
= config['header']
seasons = config['seasons']
basename = config['basename'] || config['slug']
title_tmpl = config['title']
= .split( /[ ]* [›>] [ ]*/x )
puts "==> #{.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: )
outpath = if archive
"#{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_summary ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/rsssf/project.rb', line 51
def make_schedules_summary
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 ) report.save( "#{root_dir}/README.md" )
end
|
#pages_dir ⇒ Object
22
|
# File 'lib/rsssf/project.rb', line 22
def pages_dir() "#{root_dir}/pages"; end
|