summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-08-10 23:55:40 -0400
committerPaul Duncan <pabs@pablotron.org>2016-08-10 23:55:40 -0400
commit61a66292033cc4dd76e5747106a76af26c950929 (patch)
tree6a846288c135a10eb35e54c9a09042053ff68952
parentac17e24feca48ee347fc1dbd376beaee7907a75c (diff)
downloadzip-crystal-61a66292033cc4dd76e5747106a76af26c950929.tar.bz2
zip-crystal-61a66292033cc4dd76e5747106a76af26c950929.zip
add docs for Archive getters
-rw-r--r--spec/zip_spec.cr2
-rw-r--r--src/zip.cr47
2 files changed, 48 insertions, 1 deletions
diff --git a/spec/zip_spec.cr b/spec/zip_spec.cr
index 0ca4e86..7f539cc 100644
--- a/spec/zip_spec.cr
+++ b/spec/zip_spec.cr
@@ -90,6 +90,8 @@ describe Zip do
it "reads all an archive's compressed entries" do
Zip.read(File.join(TEST_DIR, "test-many.zip")) do |zip|
+ puts "file has #{zip.size} entries"
+
zip.each do |e|
if e.dir?
diff --git a/src/zip.cr b/src/zip.cr
index be5fa56..4c4ad49 100644
--- a/src/zip.cr
+++ b/src/zip.cr
@@ -1768,7 +1768,29 @@ module Zip
include Enumerable(Entry)
include Iterable
- getter :entries, :comment
+ #
+ # Return an array of entries in this Archive.
+ #
+ # Example:
+ #
+ # Zip.read("foo.zip") do |zip|
+ # # get an array of entries in this archive
+ # entries = zip.entries
+ # end
+ #
+ getter :entries
+
+ #
+ # Get the `Archive` comment as a String.
+ #
+ # Example:
+ #
+ # Zip.read("foo.zip") do |zip|
+ # # print archive comment
+ # puts "comment: #{zip.comment}"
+ # end
+ #
+ getter :comment
#
# Create new Zip::Archive from input Zip::Source.
@@ -1920,7 +1942,30 @@ module Zip
@entries[id]?
end
+ #
+ # Iterate over the entries in this `Archive`, or, if called without
+ # a block, return a lazy iterator.
+ #
+ # Example:
+ #
+ # Zip.read("foo.zip") do |zip|
+ # zip.each do |e|
+ # type = e.dir? ? "directory" : "file"
+ # puts "#{e.path} is a #{type}"
+ # end
+ # end
+ #
delegate each, to: @entries
+
+ #
+ # Return the number of entries in this `Archive`.
+ #
+ # Example:
+ #
+ # Zip.read("foo.zip") do |zip|
+ # puts "foo.zip has #{zip.size} entries"
+ # end
+ #
delegate size, to: @entries
###################