Module: Rsssf::Utils
- Included in:
- Page, Project, ScheduleReport
- Defined in:
- lib/rsssf/utils.rb
Constant Summary collapse
- YEAR_FROM_NAME_RE =
note - add lookbehind and lookahead for boundary NOT A NUMBER!!
other will match 4 digits in 5 digits number etc. or 2 digits in 3 digits number etc. %r{ (?<! \d) ## note - no digit before allowed (?: \d{4} | \d{2} ) (?! \d) ## no digit after allowed }x
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
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rsssf/utils.rb', line 50 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 ) ## e.g. duit92.txt or duit92.html => duit92 basename = File.basename( path, File.extname( path )) year_from_name( basename ) end |
#year_from_name(name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rsssf/utils.rb', line 27 def year_from_name( name ) ## note - make sure it works for special case like: ## mex2-2010 !!! ## only match two digits (YY) or four digits (YYYY) if m=YEAR_FROM_NAME_RE.match( name ) digits = m[0].to_s num = digits.to_i(10) if digits.size == 4 ## e.g. 1980 or 2011 etc. num else ## digits.size == 2 ## e.g. 00, 20 or 99 etc. ## assume 20xx for now from 00..09 ## assume 19xx for 10..99 num <= 9 ? 2000+num : 1900+num end else fail( "no year found in name #{name}; expected two or four digits") end end |