kata 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +51 -31
- data/lib/kata.rb +12 -15
- data/spec/kata_spec.rb +0 -2
- data/spec/support/helpers/stdout_helper.rb +5 -5
- metadata +6 -6
data/README.md
CHANGED
@@ -1,41 +1,61 @@
|
|
1
1
|
## Kata ##
|
2
2
|
|
3
|
+
A kata is defined as an exercise in programming which helps hone your skills
|
4
|
+
through practice and repetition. Authoring katas is done in blogs with no
|
5
|
+
real way of testing yourself for improvement. This gem provides a DSL to
|
6
|
+
author the kata and administer it as a test providing feedback for evaluation.
|
7
|
+
|
8
|
+
### Writing a Kata ###
|
9
|
+
|
10
|
+
It is as simple as installing this gem and creating a ruby file much like
|
11
|
+
an RSpec test as illustrated below:
|
12
|
+
|
3
13
|
require 'kata'
|
4
14
|
|
5
|
-
kata "
|
6
|
-
requirement "Create
|
7
|
-
example
|
8
|
-
example "
|
9
|
-
example "
|
15
|
+
kata "My First Kata" do
|
16
|
+
requirement "Create an add method that will accept two digits as arguments" do
|
17
|
+
example "invoking with 1 and 2 returns 3"
|
18
|
+
example "invoking with 5 only returns 5"
|
19
|
+
example "invoking with no arguments returns 0"
|
10
20
|
end
|
11
|
-
|
12
|
-
|
13
|
-
example
|
14
|
-
example %q{"1,2,5,8" sums to 16}
|
21
|
+
requirement "Modify the add method to access multple digits as arguments" do
|
22
|
+
example "invoking with 1 and 2 and 3 returns 6"
|
23
|
+
example "invoking with 1 and 2 and 3 and 4 and 5 returns 15"
|
15
24
|
end
|
25
|
+
end
|
16
26
|
|
17
|
-
|
18
|
-
example %q{"1\n2\n3" sums to 6}
|
19
|
-
example %q{"2,3\n4" sums to 9}
|
20
|
-
example %q{Consecutive use of delimeters ("1,\n2") should raise an exception}
|
21
|
-
end
|
27
|
+
### Taking a Kata ###
|
22
28
|
|
23
|
-
|
24
|
-
example "The exception will list the negative number that was in the string"
|
25
|
-
example "The exception should list all negatives if there is more than one"
|
26
|
-
end
|
29
|
+
Running the kata from the command line yields:
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
wesbailey@feynman:~/kata> ruby sample.rb
|
32
|
+
My First Kata
|
33
|
+
Create an add method that will accept two digits as arguments
|
34
|
+
- invoking with 1 and 2 returns 3
|
35
|
+
- invoking with 1 returns 1
|
36
|
+
- invoking with no arguments returns 0
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
continue (Y|n):
|
39
|
+
|
40
|
+
Modify the add method to access multple digits as arguments
|
41
|
+
- invoking with 1 and 2 and 3 returns 6
|
42
|
+
- invoking with 1 and 2 and 3 and 4 and 5 returns 15
|
43
|
+
|
44
|
+
continue (Y|n):
|
45
|
+
|
46
|
+
|
47
|
+
### Completing the Kata ###
|
48
|
+
|
49
|
+
After completing the requirements of the kata continue and the report is
|
50
|
+
displayed:
|
51
|
+
|
52
|
+
Congratulations!
|
53
|
+
- Create an add method that will accept two digits as arguments 00:02:02
|
54
|
+
- Modify the add method to access multple digits as arguments 00:00:45
|
55
|
+
|
56
|
+
### Installing Kata ###
|
57
|
+
|
58
|
+
It is up on rubygems.org so add it to your bundle or do it the old fashioned
|
59
|
+
way with:
|
60
|
+
|
61
|
+
gem install kata
|
data/lib/kata.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
1
|
module Kata
|
2
|
-
|
3
|
-
class << Kata
|
4
|
-
@@input = $stdin
|
5
|
-
@@output = $stdout
|
6
|
-
@@times = []
|
7
|
-
end
|
2
|
+
@@times = []
|
8
3
|
|
9
|
-
def kata txt
|
10
|
-
|
4
|
+
def kata txt, lib = nil
|
5
|
+
puts txt
|
11
6
|
yield if block_given?
|
12
7
|
complete
|
13
8
|
end
|
14
9
|
|
15
10
|
def requirement txt
|
16
|
-
|
11
|
+
puts indent + txt
|
17
12
|
|
18
13
|
start = Time.now
|
19
14
|
|
@@ -21,7 +16,7 @@ module Kata
|
|
21
16
|
|
22
17
|
rsp = ask "\ncontinue (Y|n): ", 'y'
|
23
18
|
|
24
|
-
|
19
|
+
puts
|
25
20
|
|
26
21
|
elapsed = Time.now - start
|
27
22
|
@@times << {:title => txt, :time => elapsed}
|
@@ -30,14 +25,14 @@ module Kata
|
|
30
25
|
end
|
31
26
|
|
32
27
|
def example txt
|
33
|
-
|
28
|
+
puts indent + '- ' + txt
|
34
29
|
end
|
35
30
|
|
36
31
|
private
|
37
32
|
|
38
33
|
def ask prompt, default
|
39
|
-
|
40
|
-
|
34
|
+
print prompt
|
35
|
+
$stdin.gets.chomp || default
|
41
36
|
end
|
42
37
|
|
43
38
|
def complete status = true
|
@@ -49,8 +44,10 @@ module Kata
|
|
49
44
|
[use/3600, use/60 % 60, use % 60].map {|v| v.to_s.rjust(2,'0')}.join(':')
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
|
47
|
+
puts "\n\n#{title}"
|
48
|
+
puts @@times.inject('') {|s,p| s << "- #{p[:title][0,70].ljust(70, ' ')} #{formatter.call(p[:time]).rjust(10,' ')}\n"}
|
49
|
+
puts '-' * 70 + ' ' * 5 + '-' * 8
|
50
|
+
puts 'Total Time taking Kata'.ljust(70, ' ') + ' ' * 5 + formatter.call(@@times.inject(0) {|s,h| s += h[:time]})
|
54
51
|
end
|
55
52
|
|
56
53
|
exit 1 unless status
|
data/spec/kata_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
|
3
3
|
def capture_stdout
|
4
|
-
|
5
|
-
|
4
|
+
$stdout = StringIO.new
|
5
|
+
$stdin = StringIO.new("y\n")
|
6
6
|
yield
|
7
|
-
|
7
|
+
$stdout.string.strip
|
8
8
|
ensure
|
9
|
-
|
10
|
-
|
9
|
+
$stdout = STDOUT
|
10
|
+
$stdin = STDIN
|
11
11
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Wes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-18 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -33,8 +33,8 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
|
-
description:
|
37
|
-
email:
|
36
|
+
description: This DSL provides an easy way for you to write a code kata or pairing exercise
|
37
|
+
email: baywes@gmail.com
|
38
38
|
executables: []
|
39
39
|
|
40
40
|
extensions: []
|