Module: Rsssf::Utils
- Included in:
- Page, Repo, ScheduleReport
- Defined in:
- lib/rsssf/utils.rb
Instance Method Summary collapse
- #archive_dir_for_season(season) ⇒ Object
-
#year_from_file(path) ⇒ Object
move to Page - why? why not?.
- #year_from_name(name) ⇒ Object
Instance Method Details
#archive_dir_for_season(season) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rsssf/utils.rb', line 38 def archive_dir_for_season( season ) season = Season( season ) if season < Season('2010') # e.g. season 2009-10 ## use archive folder (w/ 1980s etc) ## get decade folder decade = season.start_year ## 1999/2000 2000 decade -= decade % 10 ## turn 1987 into 1980 etc "archive/#{decade}s/#{season.to_path}" else season.to_path end end |
#year_from_file(path) ⇒ Object
move to Page - why? why not?
8 9 10 11 12 |
# File 'lib/rsssf/utils.rb', line 8 def year_from_file( path ) extname = File.extname( path ) basename = File.basename( path, extname ) ## e.g. duit92.txt or duit92.html => duit92 year_from_name( basename ) end |
#year_from_name(name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rsssf/utils.rb', line 15 def year_from_name( name ) if name =~ /(\d+)/ digits = $1.to_s num = digits.to_i if digits.size == 4 ## e.g. 1980 or 2011 etc. num elsif digits.size == 2 ## e.g. 00, 20 or 99 etc. if num <= 16 ## assume 20xx for now from 00..16 2000+num else ## assume 19xx for now 1900+num end else fail( "no year found in name #{name}; expected two or four digits") end else fail( "no year found in name #{name}") end end |