Permalink
Browse files

declare classes, add failing tests

  • Loading branch information...
1 parent 62d9795 commit 183eaedfcf0d51c0d97b17e93900592ba2f48808 @hotarubi committed Feb 26, 2013
View
@@ -0,0 +1,9 @@
+class DirectoryCounter
+ def initialize(argv)
+ path = argv[1]
+ recursive = argv[0] == '-r'
+ end
+
+ def count
+ end
+end
View
@@ -1,5 +1,2 @@
-def recursive?
- ARGV[0] == '-r'
-end
-
-puts recursive?
+counter = DirectoryCounter.new(ARGV)
+puts SummaryPrinter.new(counter.count).print
View
Binary file not shown.
@@ -0,0 +1,12 @@
+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") }
+ end
+
+ context "with -r argument" do
+ subject { `ruby #{pwd}/directory_summary.rb -r #{pwd}/spec/fixtures` }
+ it { should == File.read("#{pwd}/spec/expectations/recursive") }
+ end
+end
@@ -0,0 +1,20 @@
+html:
+ number of files: 2
+ combined size: 1111
+ largest file: 677
+ smallest file: 434
+jpg:
+ number of files: 2
+ combined size: 165741
+ largest file: 118053
+ smallest file: 47688
+txt:
+ number of files: 3
+ combined size: 1230
+ largest file: 672
+ smallest file: 5
+zip:
+ number of files: 4
+ combined size: 139813
+ largest file: 136010
+ smallest file: 760
@@ -0,0 +1,30 @@
+css:
+ number of files: 1
+ combined size: 11
+ largest file: 11
+ smallest file: 11
+html:
+ number of files: 2
+ combined size: 1111
+ largest file: 677
+ smallest file: 434
+jpg:
+ number of files: 2
+ combined size: 165741
+ largest file: 118053
+ smallest file: 47688
+js:
+ number of files: 3
+ combined size: 4481
+ largest file: 3923
+ smallest file: 191
+txt:
+ number of files: 3
+ combined size: 1230
+ largest file: 672
+ smallest file: 5
+zip:
+ number of files: 4
+ combined size: 139813
+ largest file: 136010
+ smallest file: 760
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="utf-8"?> <!-- Generator: IcoMoon.io --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 16 16" xml:space="preserve" fill="#000000"> <path d="M 39.00,39.00l-9.00,0.00 l-6.00,9.00l-6.00-9.00L9.00,39.00 c-4.971,0.00-9.00-4.032-9.00-9.00L0.00,9.00 c0.00-4.971, 4.029-9.00, 9.00-9.00 l30.00,0.00 c 4.968,0.00, 9.00,4.029, 9.00,9.00l0.00,21.00 C 48.00,34.968, 43.968,39.00, 39.00,39.00z" ></path></svg>
Binary file not shown.
@@ -0,0 +1,4 @@
+body {
+
+}
+
View
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <link rel="stylesheet" href="css/app.css" type="text/css" charset="utf-8">
+</head>
+ <body>
+ <div id="bar-chart"></div>
+
+ <script type="text/javascript" src="js/jquery.js"></script>
+ <script type="text/javascript" src="js/raphael.js"></script>
+ <script type="text/javascript" src="js/app.js"></script>
+ </body>
+</html>
Binary file not shown.
View
@@ -0,0 +1,113 @@
+
+/*jslint white: false, onevar: true, browser: true, devel: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: false, newcap: true, immed: true */
+/*global jQuery, $, Raphael */
+
+function BarChart(domID, scale, ratio, data) {
+ if ( !(this instanceof arguments.callee) ) {
+ return new arguments.callee(arguments);
+ }
+
+ var self = this,
+ width = 100 * scale,
+ height = width * ratio,
+ bar_height = height * 0.25,
+ bar_length = width * 0.8,
+ x = width * 0.1,
+ y = height * 0.375,
+ color_orange = '#FFA05C',
+ color_red = '#FC5A5E',
+ color_blue = '#CCE6FF',
+ color_green = '#239017',
+ color_dark = '#3D3D3D'
+ bar_data = [];
+
+ self.bubblePath = "M 39.00,39.00l-9.00,0.00 l-6.00,9.00l-6.00-9.00L9.00,39.00 c-4.971,0.00-9.00-4.032-9.00-9.00L0.00,9.00 c0.00-4.971, 4.029-9.00, 9.00-9.00 l30.00,0.00 c 4.968,0.00, 9.00,4.029, 9.00,9.00l0.00,21.00 C 48.00,34.968, 43.968,39.00, 39.00,39.00z";
+
+ self.init = function() {
+ self.paper = Raphael(domID, width, height);
+ self.parseData();
+ self.draw();
+ };
+
+ self.parseData = function() {
+ if ( data.actual > data.total_benchmark ) {
+ bar_data.push([1.0, color_green, data.actual]);
+ bar_data.push([data.total_benchmark / data.actual, color_blue, data.total_benchmark]);
+ bar_data.push([data.benchmark_td / data.actual, color_orange, data.benchmark_td]);
+ } else if ( data.actual > data.benchmark_td ) {
+ bar_data.push([1.0, color_blue, data.total_benchmark]);
+ bar_data.push([data.actual / data.total_benchmark, color_green, data.actual]);
+ bar_data.push([data.benchmark_td / data.total_benchmark, color_orange, data.benchmark_td]);
+ } else {
+ bar_data.push([1.0, color_blue, data.total_benchmark]);
+ bar_data.push([data.benchmark_td / data.total_benchmark, color_red, data.benchmark_td]);
+ bar_data.push([data.actual / data.total_benchmark, color_orange, data.actual]);
+ }
+ };
+
+ self.draw = function() {
+ $(bar_data).each(function(i, d){
+ self.drawBar(d[0], d[1]);
+ self.drawTooltip(d[0], d[2]);
+ });
+ };
+
+ self.drawBar = function(proportion, color) {
+ var bar, hoverFunc, hideFunc;
+ bar = self.paper.rect(x, y, bar_length * proportion, bar_height);
+ bar.attr({
+ 'stroke-width': 0,
+ 'fill': color,
+ 'fill-opacity': 1.0,
+ 'stroke': color_dark
+ });
+ hoverFunc = function() {
+ bar.animate({'stroke-width': 1}, 1000, 'bounce');
+ };
+ hideFunc = function() {
+ bar.animate({'stroke-width': 0 }, 1000, 'bounce');
+ };
+ $(bar.node).hover(hoverFunc, hideFunc);
+ };
+
+ self.drawTooltip = function(proportion, text) {
+ var tooltip, label, hoverFunc, hideFunc, scale = 0.5;
+ tooltip = self.paper.path(self.bubblePath);
+ tooltip.translate(bar_length * proportion, - bar_height / 2);
+ tooltip.scale(scale);
+ tooltip.attr({
+ 'stroke-width': 0,
+ 'fill' : color_dark,
+ 'fill-opacity': 0.9
+ });
+
+ label = self.paper.text(bar_length * (proportion + 0.12), bar_height * 0.6, text);
+ label.attr({
+ 'fill': '#ffffff'
+ , 'font-size': 6
+ , 'font-family': "'League Gothic', 'Futura-CondensedMedium', 'Gill Sans MT Condensed', 'Arial Narrow', sans-serif"
+ });
+ label.toBack();
+ tooltip.toBack();
+
+ hoverFunc = function() {
+ tooltip.animate({scale: 0.6}, 1000, 'bounce');
+ };
+ hideFunc = function() {
+ tooltip.animate({scale: scale}, 1000, 'bounce');
+ };
+ $(tooltip.node).hover(hoverFunc, hideFunc);
+ $(label.node).hover(hoverFunc, hideFunc);
+ };
+
+ self.init();
+}
+
+var chart;
+jQuery(function () {
+
+ chart = new BarChart('bar-chart', 2.5, 0.3, {actual: 2400.0, benchmark_td: 2000.0, total_benchmark: 4000.0});
+
+});
+
+
View
@@ -0,0 +1,15 @@
+/*!
+ * jQuery JavaScript Library v1.4.2
+ * http://jquery.com/
+ *
+ * Copyright 2010, John Resig
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://jquery.org/license
+ *
+ * Includes Sizzle.js
+ * http://sizzlejs.com/
+ * Copyright 2010, The Dojo Foundation
+ * Released under the MIT, BSD, and GPL Licenses.
+ *
+ * Date: Sat Feb 13 22:33:48 2010 -0500
+ */
@@ -0,0 +1,6 @@
+/*!
+ * Raphael 1.5.2 - JavaScript Vector Library
+ *
+ * Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
+ * Licensed under the MIT (http://raphaeljs.com/license.html) license.
+ */
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1 @@
+Screening test before interviewCreate a program that, given a directory path, it creates a summary of the files in the directory. You can create the program either in Ruby or Java.The program will be invoked as follows:For Java: java DirectorySummary [-r] directory_pathFor Ruby: ruby directory_summary.rb [-r] directory_pathThe optional '-r' argument indicates that the program should work recursively through subdirectories. If the -r option is not specified, the summarywill be for the files in the given directory only, and will ignore subdirectories.The output is a summary of file types, grouped by file extension. For each extension, the program will output:
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1 @@
+The output is a summary of file types, grouped by file extension. For each extension, the program will output:For example:The identation for the lines in the summary is two spaces.If you are doing it in Ruby, submit a zip file containing a Gemfile with the gems you have used, and the source code file.If you are doing it in Java, submit a zip file containing two directories, src and lib. Put your code under the src directory, and any jar you may have used under the lib directory.Please complete this assignment and return to us within 48 hours.
View
@@ -0,0 +1 @@
+test3
View
@@ -0,0 +1,7 @@
+class SummaryPrinter
+ def initialize(list)
+ end
+
+ def print
+ end
+end

0 comments on commit 183eaed

Please sign in to comment.