Pickaxe 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +12 -0
- data/bin/pickaxe +4 -21
- data/lib/pickaxe.rb +4 -5
- data/lib/pickaxe/main.rb +34 -14
- data/lib/pickaxe/test.rb +25 -12
- metadata +6 -4
data/Gemfile.lock
ADDED
data/bin/pickaxe
CHANGED
@@ -33,15 +33,11 @@ END_OF_BANNER
|
|
33
33
|
opts.on("--select [NUMBER]", "Select certain number of questions") do |v|
|
34
34
|
options[:select] = Integer(v)
|
35
35
|
end
|
36
|
-
|
37
|
-
opts.on("-
|
38
|
-
options[:
|
36
|
+
|
37
|
+
opts.on("--full-test", "Checks test after all questions are answered") do |v|
|
38
|
+
options[:full_test] = true
|
39
39
|
end
|
40
40
|
|
41
|
-
opts.on("--list-builtin", "Lists builtin test names") do |v|
|
42
|
-
options[:list_builtin] = true
|
43
|
-
end
|
44
|
-
|
45
41
|
opts.on_tail("--version", "Show version") do
|
46
42
|
puts "pickaxe version #{Pickaxe::VERSION}"
|
47
43
|
exit
|
@@ -53,21 +49,8 @@ END_OF_BANNER
|
|
53
49
|
end
|
54
50
|
end.parse!
|
55
51
|
|
56
|
-
if options[:list_builtin]
|
57
|
-
puts(Dir.glob(File.dirname(__FILE__) + "/../tests/*.#{options[:extension] || "txt"}").collect do |file|
|
58
|
-
File.basename(file)
|
59
|
-
end.join(" "))
|
60
|
-
exit
|
61
|
-
end
|
62
|
-
|
63
|
-
paths = if options[:builtin]
|
64
|
-
File.expand_path(File.dirname(__FILE__) + "/../tests")
|
65
|
-
else
|
66
|
-
ARGV
|
67
|
-
end
|
68
|
-
|
69
52
|
begin
|
70
|
-
Pickaxe::Main.new(
|
53
|
+
Pickaxe::Main.new(ARGV, options)
|
71
54
|
rescue Pickaxe::PickaxeError => e
|
72
55
|
$stderr.puts(("! " + e.message).color(:red))
|
73
56
|
exit(e.status_code)
|
data/lib/pickaxe.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
require "bundler"
|
2
|
+
require "bundler/setup"
|
3
|
+
Bundler.require(:default)
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'active_support/all'
|
5
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
7
6
|
|
8
7
|
module Pickaxe
|
9
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.3.1"
|
10
9
|
|
11
10
|
class PickaxeError < StandardError
|
12
11
|
attr_reader :status_code
|
data/lib/pickaxe/main.rb
CHANGED
@@ -2,24 +2,40 @@ module Pickaxe
|
|
2
2
|
class Main
|
3
3
|
class NoTests < PickaxeError; status_code(1) ; end
|
4
4
|
|
5
|
+
cattr_accessor :options
|
6
|
+
|
7
|
+
END_OF_TEST_MESSAGE = <<END_OF_TEST
|
8
|
+
This is the end of this test and You can now jump back to
|
9
|
+
any question and check (or change) Your answers.
|
10
|
+
|
11
|
+
Hit [ENTER] to rate the test.
|
12
|
+
END_OF_TEST
|
13
|
+
|
5
14
|
def initialize(paths, options = {})
|
6
15
|
raise NoTests, "no tests to run" if paths.empty?
|
7
|
-
@test = Test.new(options, *paths)
|
8
|
-
@questions = @test.shuffled_questions
|
9
|
-
@answers = Hash.new([])
|
10
16
|
|
17
|
+
Main.options = options
|
18
|
+
|
19
|
+
@test = Test.new(*paths)
|
20
|
+
@questions = @test.shuffled_questions
|
21
|
+
@answers = Hash.new([])
|
11
22
|
@started_at = Time.now
|
12
23
|
@current_index = 0
|
13
|
-
|
24
|
+
|
25
|
+
while @current_index < @questions.length + (Main.options[:full_test] ? 1 : 0) do
|
14
26
|
@question = @questions[@current_index]
|
15
27
|
|
16
|
-
|
17
|
-
|
28
|
+
unless @question.nil?
|
29
|
+
puts "#{@current_index+1} / #{@questions.length}\t\tFrom: #{@question.file}\t\tTime spent: #{spent?}"
|
30
|
+
puts @question.answered(@answers[@question])
|
31
|
+
else
|
32
|
+
puts END_OF_TEST_MESSAGE
|
33
|
+
end
|
18
34
|
|
19
35
|
until (line = prompt?).nil? or command(line)
|
20
36
|
# empty
|
21
37
|
end
|
22
|
-
|
38
|
+
|
23
39
|
break if puts or line.nil?
|
24
40
|
end
|
25
41
|
|
@@ -28,10 +44,9 @@ module Pickaxe
|
|
28
44
|
|
29
45
|
#
|
30
46
|
# Available commands
|
31
|
-
#
|
47
|
+
# @ question jumps to given question
|
32
48
|
# <+ moves back one question
|
33
49
|
# >+ moves forward one question
|
34
|
-
# ! a [ b ...] answers the question and forces to show correct answers
|
35
50
|
# a [ b ...] answers the question
|
36
51
|
# ? shows help
|
37
52
|
#
|
@@ -55,10 +70,15 @@ module Pickaxe
|
|
55
70
|
error "You are at last question"
|
56
71
|
end
|
57
72
|
when "\n" then
|
58
|
-
|
73
|
+
if Main.options[:full_test] and @question.nil?
|
74
|
+
Main.options[:full_test] = false
|
75
|
+
Main.options[:force_show_answers] = true
|
76
|
+
|
77
|
+
@current_index = 0
|
78
|
+
else
|
79
|
+
@current_index += 1
|
80
|
+
end
|
59
81
|
true
|
60
|
-
when /^\s*!\s*(.+)/ then
|
61
|
-
raise NotImplementedError
|
62
82
|
when /\?/ then
|
63
83
|
puts <<END_OF_HELP
|
64
84
|
|
@@ -66,14 +86,14 @@ Available commands (whitespace does not matter):
|
|
66
86
|
@ question jumps to given question
|
67
87
|
< moves back one question
|
68
88
|
> moves forward one question
|
69
|
-
|
70
|
-
! a [ b ...] answers the question and forces reveal correct answers
|
89
|
+
a [ b ...] answers the question
|
71
90
|
? shows help
|
72
91
|
|
73
92
|
END_OF_HELP
|
74
93
|
false
|
75
94
|
else
|
76
95
|
@answers[@question] = line.split(/\s+/).collect(&:strip)
|
96
|
+
puts @question.check?(@answers[@question]) unless Main.options[:full_test]
|
77
97
|
@current_index += 1
|
78
98
|
true
|
79
99
|
end
|
data/lib/pickaxe/test.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module Pickaxe
|
2
|
+
|
3
|
+
class PathError < PickaxeError; status_code(1) ; end
|
4
|
+
class MissingAnswers < PickaxeError; status_code(2) ; end
|
5
|
+
class BadAnswer < PickaxeError; status_code(3) ; end
|
6
|
+
|
2
7
|
#
|
3
8
|
# Test is a file in which questions are separated by a blank line.
|
4
9
|
# Each question has content (first line), and answers remaining lines.
|
@@ -20,18 +25,13 @@ module Pickaxe
|
|
20
25
|
# Ruby-comments and C-comments
|
21
26
|
COMMENTS_RE = /^#.*|^\/\/.*/
|
22
27
|
|
23
|
-
|
24
|
-
class MissingAnswers < PickaxeError; status_code(2) ; end
|
25
|
-
class BadAnswer < PickaxeError; status_code(3) ; end
|
26
|
-
|
27
|
-
def initialize(options, *files)
|
28
|
-
@options = options
|
28
|
+
def initialize(*files)
|
29
29
|
@files = files.collect do |file_or_directory|
|
30
30
|
raise PathError, "file or directory '#{file_or_directory}' does not exist" unless File.exist?(file_or_directory)
|
31
31
|
if File.file?(file_or_directory)
|
32
32
|
file_or_directory
|
33
33
|
else
|
34
|
-
Dir.glob("#{file_or_directory}/*.#{
|
34
|
+
Dir.glob("#{file_or_directory}/*.#{Main.options[:extension] || "txt"}")
|
35
35
|
end
|
36
36
|
end.flatten
|
37
37
|
|
@@ -53,14 +53,14 @@ module Pickaxe
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def shuffled_questions
|
56
|
-
questions = if
|
56
|
+
questions = if Main.options[:sorted]
|
57
57
|
@questions
|
58
58
|
else
|
59
59
|
@questions.shuffle
|
60
60
|
end
|
61
61
|
|
62
|
-
@selected = if
|
63
|
-
questions[0...(
|
62
|
+
@selected = if Main.options[:select]
|
63
|
+
questions[0...(Main.options[:select])]
|
64
64
|
else
|
65
65
|
questions
|
66
66
|
end
|
@@ -97,7 +97,8 @@ module Pickaxe
|
|
97
97
|
"#{self.content.word_wrap}\n\n" + self.answers.collect do |answer|
|
98
98
|
selected = indices.include?(answer.index)
|
99
99
|
line = (selected ? ">> " : " ") + answer.to_s
|
100
|
-
|
100
|
+
|
101
|
+
if Main.options[:force_show_answers] or (not indices.blank? and not Main.options[:full_test]) then
|
101
102
|
if selected and answer.correctness
|
102
103
|
line.color(:green)
|
103
104
|
elsif not selected and answer.correctness
|
@@ -110,7 +111,19 @@ module Pickaxe
|
|
110
111
|
end
|
111
112
|
|
112
113
|
def correct?(given)
|
113
|
-
given.sort ==
|
114
|
+
given.sort == correct_answers
|
115
|
+
end
|
116
|
+
|
117
|
+
def correct_answers
|
118
|
+
answers.select(&:correctness).collect(&:index).sort
|
119
|
+
end
|
120
|
+
|
121
|
+
def check?(given)
|
122
|
+
if correct?(given)
|
123
|
+
"Correct!".color(:green)
|
124
|
+
else
|
125
|
+
"Incorrect! Correct was: #{correct_answers.join(", ")}".color(:red)
|
126
|
+
end
|
114
127
|
end
|
115
128
|
end
|
116
129
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Pickaxe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 1
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dawid Fatyga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.markdown
|
76
76
|
- Gemfile
|
77
|
+
- Gemfile.lock
|
77
78
|
files:
|
78
79
|
- lib/pickaxe.rb
|
79
80
|
- lib/pickaxe/test.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- bin/pickaxe
|
85
86
|
- README.markdown
|
86
87
|
- Gemfile
|
88
|
+
- Gemfile.lock
|
87
89
|
has_rdoc: true
|
88
90
|
homepage: https://github.com/dejw/pickaxe
|
89
91
|
licenses: []
|