Skip to content

Instantly share code, notes, and snippets.

@jazzido
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzido/8807800 to your computer and use it in GitHub Desktop.
Save jazzido/8807800 to your computer and use it in GitHub Desktop.
# +files+ es un string con nombres de archivo, uno por línea
files = <<-FILES
~/Dropbox/Indec-informa/pdf/iijul12[1].pdf
~/Dropbox/Indec-informa/pdf/iiago12[1].pdf
~/Dropbox/Indec-informa/pdf/iifeb09.pdf
~/Dropbox/Indec-informa/pdf/iidic11[1].pdf
~/Dropbox/Indec-informa/pdf/iiene12[1].pdf
~/Dropbox/Indec-informa/pdf/iioct11[1].pdf
FILES
meses = %w(ene feb mar abr may jun jul ago sep oct nov dic)
re = /ii(...)(\d\d).*\.pdf$/
puts files.split("\n").map { |f|
mes, anio = f.match(re).captures
"#{2000 + anio.to_i}-#{'%02i' % (meses.index(mes.downcase) + 1)},#{f}"
}
# Escribe esto a stdout:
# 2012-07,~/Dropbox/Indec-informa/pdf/iijul12[1].pdf
# 2012-08,~/Dropbox/Indec-informa/pdf/iiago12[1].pdf
# 2009-02,~/Dropbox/Indec-informa/pdf/iifeb09.pdf
# 2011-12,~/Dropbox/Indec-informa/pdf/iidic11[1].pdf
# 2012-01,~/Dropbox/Indec-informa/pdf/iiene12[1].pdf
# 2011-10,~/Dropbox/Indec-informa/pdf/iioct11[1].pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment