Module: Archivededup::FileNamePickerByDate
- Defined in:
- lib/archivededup/filepicker.rb
Constant Summary collapse
- @@times =
[ /(\d\d\d\d)-(\d?\d)-\d?\d/, # eg 2021-09-08 /(\d\d\d\d)(\d\d)\d\d/, # eg 20210908 /(\d\d\d\d)-(\d\d)/, # eg 2021-09 /(\d\d\d\d)(\d\d)/, # eg 202109 /(\d\d\d\d)/, # eg 2021 ]
Class Method Summary collapse
Class Method Details
.call(a, b) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/archivededup/filepicker.rb', line 30 def self.call(a, b) last_compare = 0 @@times.find do |re| ma = goodmatch?(re.match(a)) mb = goodmatch?(re.match(b)) if ma if mb false else # Pick a as better. last_compare = -1 true end else if mb # Pick b as better. last_compare = 1 true else false end end end last_compare end |
.goodmatch?(m) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/archivededup/filepicker.rb', line 17 def self.goodmatch?(m) return false if m.nil? year = m.length > 1? m[1].to_i : 0 month = m.length > 2? m[2].to_i : 0 return false if year < 1979 return false if year > 2100 return false if month < 0 return false if month > 12 true end |