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 ADDED
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.0.1)
5
+ i18n (0.4.2)
6
+
7
+ PLATFORMS
8
+ ruby
9
+
10
+ DEPENDENCIES
11
+ activesupport
12
+ i18n
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("-b", "--builtin", "Runs builtin tests") do |v|
38
- options[:builtin] = true
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(paths, options)
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
- Bundler.setup(:default)
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.2.1"
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
- while @current_index < @questions.length do
24
+
25
+ while @current_index < @questions.length + (Main.options[:full_test] ? 1 : 0) do
14
26
  @question = @questions[@current_index]
15
27
 
16
- puts "#{@current_index+1} / #{@questions.length}\t\tFrom: #{@question.file}\t\tTime spent: #{spent?}"
17
- puts @question.answered(@answers[@question])
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
- # ^ question jumps to given question
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
- @current_index += 1
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
- a [ b ...] answers the question
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
- class PathError < PickaxeError; status_code(1) ; end
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}/*.#{@options[:extension] || "txt"}")
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 @options[:sorted]
56
+ questions = if Main.options[:sorted]
57
57
  @questions
58
58
  else
59
59
  @questions.shuffle
60
60
  end
61
61
 
62
- @selected = if @options[:select]
63
- questions[0...(@options[:select])]
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
- unless indices.blank?
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 == answers.select(&:correctness).collect(&:index).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: 21
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 1
10
- version: 0.2.1
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-16 00:00:00 +01:00
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: []