Class: Dabcup::Storage::Dump

Inherits:
Object
  • Object
show all
Defined in:
lib/dabcup/storage/dump.rb

Constant Summary collapse

IGNORED_NAMES =
%w(. ..).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Dump

Returns a new instance of Dump.



13
14
15
16
# File 'lib/dabcup/storage/dump.rb', line 13

def initialize(attrs = {})
  self.name = attrs[:name]
  self.size = attrs[:size]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/dabcup/storage/dump.rb', line 6

def name
  @name
end

#sizeObject

Returns the value of attribute size.



7
8
9
# File 'lib/dabcup/storage/dump.rb', line 7

def size
  @size
end

Class Method Details

.valid_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/dabcup/storage/dump.rb', line 9

def self.valid_name?(name)
  !IGNORED_NAMES.include?(name)
end

Instance Method Details

#==(dump) ⇒ Object



24
25
26
# File 'lib/dabcup/storage/dump.rb', line 24

def ==(dump)
  dump && name == dump.name && size == dump.size
end

#created_atObject



18
19
20
21
22
# File 'lib/dabcup/storage/dump.rb', line 18

def created_at
  Time.parse(name)
rescue ArgumentError
  nil # Invalid date => ignore file name
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dabcup/storage/dump.rb', line 28

def valid?
  self.class.valid_name?(name) && created_at != nil
end