Class: Qdumpfs::BackupDir

Inherits:
Object
  • Object
show all
Defined in:
lib/qdumpfs/option.rb

Overview

日毎のバックアップフォルダに対応

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBackupDir

Returns a new instance of BackupDir.



30
31
32
# File 'lib/qdumpfs/option.rb', line 30

def initialize
  @keep = false
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



33
34
35
# File 'lib/qdumpfs/option.rb', line 33

def date
  @date
end

#keepObject

Returns the value of attribute keep.



33
34
35
# File 'lib/qdumpfs/option.rb', line 33

def keep
  @keep
end

#pathObject

Returns the value of attribute path.



33
34
35
# File 'lib/qdumpfs/option.rb', line 33

def path
  @path
end

Class Method Details

.dump(dirs) ⇒ Object



24
25
26
27
28
# File 'lib/qdumpfs/option.rb', line 24

def self.dump(dirs)
  dirs.each do |dir|
    puts dir
  end
end

.find(backup_dirs, from_date, to_date) ⇒ Object



20
21
22
# File 'lib/qdumpfs/option.rb', line 20

def self.find(backup_dirs, from_date, to_date)
  backup_dirs.select{|backup_dir| backup_dir.date >= from_date && backup_dir.date <= to_date}
end

.scan_backup_dirs(target_dir) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/qdumpfs/option.rb', line 5

def self.scan_backup_dirs(target_dir)
  backup_dirs = []
  Dir.glob("#{target_dir}/[0-9][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]").sort.each do |path|
    if  File.directory?(path) && path =~ /(\d\d\d\d)\/(\d\d)\/(\d\d)/
      #        puts "Backup dir: #{path}"

      backup_dir = BackupDir.new
      backup_dir.path = path
      backup_dir.date = Date.new($1.to_i, $2.to_i, $3.to_i)
      backup_dirs << backup_dir
    end
  end
  backup_dirs.sort_by!{|backup_dir| backup_dir.date}
  backup_dirs
end

Instance Method Details

#to_sObject



35
36
37
# File 'lib/qdumpfs/option.rb', line 35

def to_s
  "path=#{@path} date=#{@date} keep=#{@keep}"
end