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.
-
#oldest_content ⇒ Object
readonly
Returns the value of attribute oldest_content.
-
#total_size ⇒ Object
readonly
Returns the value of attribute total_size.
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.
15 16 17 18 19 |
# File 'lib/s3grep/directory_info.rb', line 15 def initialize(directory) @total_size = 0 @num_files = 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 |
#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 |
Class Method Details
.get(directory) ⇒ Object
10 11 12 13 |
# File 'lib/s3grep/directory_info.rb', line 10 def self.get(directory) info = new(directory) info.process(directory) end |
Instance Method Details
#first_file ⇒ Object
45 46 47 |
# File 'lib/s3grep/directory_info.rb', line 45 def first_file @oldest_content && @oldest_content[:key] end |
#first_modified ⇒ Object
41 42 43 |
# File 'lib/s3grep/directory_info.rb', line 41 def first_modified @oldest_content && @oldest_content[:last_modified] end |
#last_modified ⇒ Object
33 34 35 |
# File 'lib/s3grep/directory_info.rb', line 33 def last_modified @newest_content && @newest_content[:last_modified] end |
#newest_file ⇒ Object
37 38 39 |
# File 'lib/s3grep/directory_info.rb', line 37 def newest_file @newest_content && @newest_content[:key] end |
#process(directory) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/s3grep/directory_info.rb', line 21 def process(directory) directory.each_content do |content| @num_files += 1 @total_size += content[:size] set_newest(content) set_oldest(content) end self end |
#set_newest(content) ⇒ Object
55 56 57 58 59 |
# File 'lib/s3grep/directory_info.rb', line 55 def set_newest(content) if @newest_content.nil? || @newest_content[:last_modified] < content[:last_modified] @newest_content = content end end |
#set_oldest(content) ⇒ Object
61 62 63 64 65 |
# File 'lib/s3grep/directory_info.rb', line 61 def set_oldest(content) if @oldest_content.nil? || @oldest_content[:last_modified] > content[:last_modified] @oldest_content = content end end |
#set_path(directory) ⇒ Object
49 50 51 52 53 |
# File 'lib/s3grep/directory_info.rb', line 49 def set_path(directory) uri = URI(directory.s3_url) @bucket = uri.host @base_prefix = CGI.unescape(uri.path[1..-1] || '') end |