class Lister

Public Instance Methods

entries() click to toggle source
# File lib/lister.rb, line 4
def entries()
  return Dir.entries(self.to_s).reject {|f| f[0] == '.'}
end
prepared_entries() click to toggle source
# File lib/lister.rb, line 8
def prepared_entries()
  out = { }
  self.entries.each do |fp|
    m = /\.(S[0-9][0-9])(E[0-9].*)\./.match(fp)
    next if m.nil?
    season = m[1].to_s
    serie  = Regexp.new('(.*)[\.]%s' % season).match(fp)[1].reformat

    path   = Pathname.new(self).join(fp).realpath
    parts  = fp.split(/(\.|\s|-|)(?=[\w])/)

    out[serie] = { } if !out.include?(serie)
    out[serie][season] = [] if !out[serie].include?(season)

    if path.directory?
      path.entries.each do |f|
        f = path.join(f)
        out[serie][season] << f.to_s if f.file?
      end
    else
      out[serie][season] << path.to_s if path.file?
    end
  end
  return out
end