Class: S3Grep::DirectoryInfo
- Inherits:
-
Object
- Object
- S3Grep::DirectoryInfo
- Defined in:
- lib/s3grep/directory_info.rb
Instance Attribute Summary collapse
-
#base_prefix ⇒ Object
readonly
Returns the value of attribute base_prefix.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#newest_content ⇒ Object
readonly
Returns the value of attribute newest_content.
-
#num_files ⇒ Object
readonly
Returns the value of attribute num_files.
-
#num_files_by_storage_class ⇒ Object
readonly
Returns the value of attribute num_files_by_storage_class.
-
#oldest_content ⇒ Object
readonly
Returns the value of attribute oldest_content.
-
#total_size ⇒ Object
readonly
Returns the value of attribute total_size.
-
#total_size_by_storage_class ⇒ Object
readonly
Returns the value of attribute total_size_by_storage_class.
Class Method Summary collapse
Instance Method Summary collapse
- #first_file ⇒ Object
- #first_modified ⇒ Object
-
#initialize(directory) ⇒ DirectoryInfo
constructor
A new instance of DirectoryInfo.
- #last_modified ⇒ Object
- #newest_file ⇒ Object
- #process(directory) ⇒ Object
- #set_newest(content) ⇒ Object
- #set_oldest(content) ⇒ Object
- #set_path(directory) ⇒ Object
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_prefix ⇒ Object (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 |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/s3grep/directory_info.rb', line 3 def bucket @bucket end |
#newest_content ⇒ Object (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_files ⇒ Object (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_class ⇒ Object (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_content ⇒ Object (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_size ⇒ Object (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_class ⇒ Object (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_file ⇒ Object
52 53 54 |
# File 'lib/s3grep/directory_info.rb', line 52 def first_file @oldest_content && @oldest_content[:key] end |
#first_modified ⇒ Object
48 49 50 |
# File 'lib/s3grep/directory_info.rb', line 48 def first_modified @oldest_content && @oldest_content[:last_modified] end |
#last_modified ⇒ Object
40 41 42 |
# File 'lib/s3grep/directory_info.rb', line 40 def last_modified @newest_content && @newest_content[:last_modified] end |
#newest_file ⇒ Object
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 |