Permalink
Browse files

add print function, add gemfile, rvmrc, readme

  • Loading branch information...
1 parent e87576b commit f71c8f8951c6421f9e4f626117756c2517e04558 @hotarubi committed Feb 26, 2013
Showing with 54 additions and 3 deletions.
  1. +1 −0 .rvmrc
  2. +3 −0 Gemfile
  3. +18 −0 Gemfile.lock
  4. +16 −1 README.md
  5. +3 −0 directory_summary.rb
  6. +1 −0 spec/directory_summary_spec.rb
  7. +1 −1 spec/expectations/non_recursive
  8. +1 −1 spec/expectations/recursive
  9. +10 −0 summary_printer.rb
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm --create use 1.8.7-p334@directory_summary
View
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem 'rspec'
View
@@ -0,0 +1,18 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ diff-lcs (1.2.1)
+ rspec (2.13.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
+ rspec-core (2.13.0)
+ rspec-expectations (2.13.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.13.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rspec
View
@@ -1,2 +1,17 @@
directory_summary
-=================
+=================
+If RVM is installed, please select yes when rvm script run to create gem set especially for this project.
+
+All the functions and tests pass under ruby 1.8.7-p334 and 1.9.3-p194.
+
+Please unzip the file and run
+
+`ruby directory_summary.rb [-r] directory_path`
+
+to check the function.
+
+To run test, please type
+
+`bundle install`
+and then
+`bundle exec rspec spec/directory_summary_spec.rb`
View
@@ -1,2 +1,5 @@
+require './directory_counter'
+require './summary_printer'
+
counter = DirectoryCounter.new(ARGV)
puts SummaryPrinter.new(counter.count).print
@@ -1,5 +1,6 @@
describe "output a summary of the files in the directory" do
let(:pwd) { ENV['PWD'] }
+
context "without -r argument" do
subject { `ruby #{pwd}/directory_summary.rb #{pwd}/spec/fixtures` }
it { should == File.read("#{pwd}/spec/expectations/non_recursive") }
@@ -17,4 +17,4 @@ zip:
number of files: 4
combined size: 139813
largest file: 136010
- smallest file: 760
+ smallest file: 760
@@ -27,4 +27,4 @@ zip:
number of files: 4
combined size: 139813
largest file: 136010
- smallest file: 760
+ smallest file: 760
View
@@ -1,7 +1,17 @@
class SummaryPrinter
def initialize(map)
+ @map = map
end
def print
+ @map.map {|k, v|
+ <<-TEMPLATE.gsub(/^ {8}/, '')
+ #{k}:
+ number of files: #{v['num']}
+ combined size: #{v['total']}
+ largest file: #{v['max']}
+ smallest file: #{v['min']}
+ TEMPLATE
+ }.sort.join
end
end

0 comments on commit f71c8f8

Please sign in to comment.