Module: DirectoryHelpers
- Defined in:
- lib/images/helpers/directory_helpers.rb
Overview
Directory
Class Method Summary collapse
- .cree_le(dossier) ⇒ Object
- .defini_dossier_par(extension) ⇒ Object
- .get_date(nom_dossier) ⇒ Object
- .nombre_fichiers(dossier) ⇒ Object
Class Method Details
.cree_le(dossier) ⇒ Object
15 16 17 18 |
# File 'lib/images/helpers/directory_helpers.rb', line 15 def self.cree_le(dossier) FileUtils.mkdir_p(dossier) if dossier != "" && !Dir.exist?(dossier) dossier end |
.defini_dossier_par(extension) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/images/helpers/directory_helpers.rb', line 20 def self.defini_dossier_par(extension) if extension.downcase == ".jpeg" "JPG" else extension[/[a-zA-Z0-9]+/].upcase end end |
.get_date(nom_dossier) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/images/helpers/directory_helpers.rb', line 8 def self.get_date(nom_dossier) chemins_dossier = nom_dossier.split("/") annee = chemins_dossier.select { |v| v =~ /^([0-9]{4})$/ } mois = chemins_dossier.select { |v| v =~ /^([0-9]{2})$/ } DateTime.new(annee[0].to_i, mois[0].to_i, 1, 0, 0, 0) end |
.nombre_fichiers(dossier) ⇒ Object
28 29 30 |
# File 'lib/images/helpers/directory_helpers.rb', line 28 def self.nombre_fichiers(dossier) Dir.glob(File.join(dossier, "**", "*")).select { |file| File.file?(file) }.count end |