Class: ToiletTracker::Utils::ZipHandler
- Inherits:
-
Object
- Object
- ToiletTracker::Utils::ZipHandler
show all
- Defined in:
- lib/toilet_tracker/utils/zip_handler.rb
Defined Under Namespace
Classes: ChatFileNotFoundError, ZipError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(zip_path) ⇒ ZipHandler
Returns a new instance of ZipHandler.
21
22
23
24
|
# File 'lib/toilet_tracker/utils/zip_handler.rb', line 21
def initialize(zip_path)
@zip_path = zip_path
validate_zip_file!
end
|
Class Method Details
13
14
15
|
# File 'lib/toilet_tracker/utils/zip_handler.rb', line 13
def self.(zip_path)
new(zip_path).
end
|
.zip_file?(file_path) ⇒ Boolean
17
18
19
|
# File 'lib/toilet_tracker/utils/zip_handler.rb', line 17
def self.zip_file?(file_path)
File.extname(file_path).downcase == ".zip"
end
|
Instance Method Details
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/toilet_tracker/utils/zip_handler.rb', line 26
def
chat_entries = find_chat_entries
raise ChatFileNotFoundError, "No _chat.txt file found in zip archive" if chat_entries.empty?
chat_entry = if chat_entries.size > 1
chat_entries.min_by { |entry| entry.name.count("/") }
else
chat_entries.first
end
(chat_entry)
end
|