Class: S3Grep::DirectoryInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/s3grep/directory_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ DirectoryInfo

Returns a new instance of DirectoryInfo.



17
18
19
20
21
22
23
# File 'lib/s3grep/directory_info.rb', line 17

def initialize(directory)
  @total_size = 0
  @num_files = 0
  @num_files_by_storage_class = Hash.new(0)
  @total_size_by_storage_class = Hash.new(0)
  set_path(directory)
end

Instance Attribute Details

#base_prefixObject (readonly)

Returns the value of attribute base_prefix.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def base_prefix
  @base_prefix
end

#bucketObject (readonly)

Returns the value of attribute bucket.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def bucket
  @bucket
end

#newest_contentObject (readonly)

Returns the value of attribute newest_content.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def newest_content
  @newest_content
end

#num_filesObject (readonly)

Returns the value of attribute num_files.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def num_files
  @num_files
end

#num_files_by_storage_classObject (readonly)

Returns the value of attribute num_files_by_storage_class.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def num_files_by_storage_class
  @num_files_by_storage_class
end

#oldest_contentObject (readonly)

Returns the value of attribute oldest_content.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def oldest_content
  @oldest_content
end

#total_sizeObject (readonly)

Returns the value of attribute total_size.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def total_size
  @total_size
end

#total_size_by_storage_classObject (readonly)

Returns the value of attribute total_size_by_storage_class.



3
4
5
# File 'lib/s3grep/directory_info.rb', line 3

def total_size_by_storage_class
  @total_size_by_storage_class
end

Class Method Details

.get(directory) ⇒ Object



12
13
14
15
# File 'lib/s3grep/directory_info.rb', line 12

def self.get(directory)
  info = new(directory)
  info.process(directory)
end

Instance Method Details

#first_fileObject



52
53
54
# File 'lib/s3grep/directory_info.rb', line 52

def first_file
  @oldest_content && @oldest_content[:key]
end

#first_modifiedObject



48
49
50
# File 'lib/s3grep/directory_info.rb', line 48

def first_modified
  @oldest_content && @oldest_content[:last_modified]
end

#last_modifiedObject



40
41
42
# File 'lib/s3grep/directory_info.rb', line 40

def last_modified
  @newest_content && @newest_content[:last_modified]
end

#newest_fileObject



44
45
46
# File 'lib/s3grep/directory_info.rb', line 44

def newest_file
  @newest_content && @newest_content[:key]
end

#process(directory) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/s3grep/directory_info.rb', line 25

def process(directory)
  directory.each_content do |content|
    @num_files += 1
    @total_size += content[:size]

    @num_files_by_storage_class[content[:storage_class]] += 1
    @total_size_by_storage_class[content[:storage_class]] += content[:size]

    set_newest(content)
    set_oldest(content)
  end

  self
end

#set_newest(content) ⇒ Object



62
63
64
65
66
# File 'lib/s3grep/directory_info.rb', line 62

def set_newest(content)
  if @newest_content.nil? || @newest_content[:last_modified] < content[:last_modified]
    @newest_content = content
  end
end

#set_oldest(content) ⇒ Object



68
69
70
71
72
# File 'lib/s3grep/directory_info.rb', line 68

def set_oldest(content)
  if @oldest_content.nil? || @oldest_content[:last_modified] > content[:last_modified]
    @oldest_content = content
  end
end

#set_path(directory) ⇒ Object



56
57
58
59
60
# File 'lib/s3grep/directory_info.rb', line 56

def set_path(directory)
  uri = URI(directory.s3_url)
  @bucket = uri.host
  @base_prefix = CGI.unescape(uri.path[1..-1] || '')
end