Module: Rsssf::Utils
Instance Method Summary collapse
- #archive_dir_for_year(year) ⇒ Object
- #year_from_file(path) ⇒ Object
- #year_from_name(name) ⇒ Object
- #year_to_season(year) ⇒ Object
Instance Method Details
#archive_dir_for_year(year) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rsssf/utils.rb', line 56 def archive_dir_for_year( year ) season = year_to_season( year ) if year <= 2010 # e.g. season 2009-10 ## use archive folder (w/ 1980s etc) ## get decade folder decade = year-1 decade -= decade % 10 ## turn 1987 into 1980 etc "archive/#{decade}s/#{season}" else season end end |
#year_from_file(path) ⇒ Object
6 7 8 9 10 |
# File 'lib/rsssf/utils.rb', line 6 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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rsssf/utils.rb', line 13 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 |
#year_to_season(year) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rsssf/utils.rb', line 35 def year_to_season( year ) ## todo: require four digit years? why? why not?? ## e.g. 64 => 1963-64 ## 2011 => 2010-11 etc. if year <= 16 ## assume 20xx for now from 00..16 year += 2000 elsif year <= 99 year += 1900 else # use as is; assume four digit year end year_prev = year-1 "%4d-%02d" % [year_prev, year%100] ## e.g. return 1974-75 end |