Pickaxe 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/pickaxe.rb +1 -1
 - data/lib/pickaxe/cli.rb +8 -0
 - data/lib/pickaxe/main.rb +47 -32
 - data/lib/pickaxe/test.rb +6 -3
 - metadata +4 -4
 
    
        data/lib/pickaxe.rb
    CHANGED
    
    
    
        data/lib/pickaxe/cli.rb
    CHANGED
    
    | 
         @@ -31,6 +31,10 @@ END_OF_BANNER 
     | 
|
| 
       31 
31 
     | 
    
         
             
            		options[:full_test] = true
         
     | 
| 
       32 
32 
     | 
    
         
             
            	end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
      
 34 
     | 
    
         
            +
            	opts.on("--repeat-incorrect", "Repeat questions answered incorrectly") do |v|
         
     | 
| 
      
 35 
     | 
    
         
            +
            		options[:repeat_incorrect] = true
         
     | 
| 
      
 36 
     | 
    
         
            +
            	end
         
     | 
| 
      
 37 
     | 
    
         
            +
            	
         
     | 
| 
       34 
38 
     | 
    
         
             
            	opts.on("--strict", "Quit on syntax error in test file") do |v|
         
     | 
| 
       35 
39 
     | 
    
         
             
            		options[:strict] = true
         
     | 
| 
       36 
40 
     | 
    
         
             
            	end
         
     | 
| 
         @@ -56,6 +60,10 @@ end 
     | 
|
| 
       56 
60 
     | 
    
         | 
| 
       57 
61 
     | 
    
         
             
            begin
         
     | 
| 
       58 
62 
     | 
    
         
             
            	parser.parse!
         
     | 
| 
      
 63 
     | 
    
         
            +
            	if options[:full_test] and options[:repeat_incorrect]
         
     | 
| 
      
 64 
     | 
    
         
            +
            		$stderr.puts(("! --full-test disables the --repeat-incorrect option" ).color(:yellow))
         
     | 
| 
      
 65 
     | 
    
         
            +
            		options[:repeat_incorrect] = false
         
     | 
| 
      
 66 
     | 
    
         
            +
            	end
         
     | 
| 
       59 
67 
     | 
    
         
             
            	Pickaxe::Main.new(ARGV, options)
         
     | 
| 
       60 
68 
     | 
    
         
             
            rescue Pickaxe::PickaxeError, OptionParser::InvalidOption => e
         
     | 
| 
       61 
69 
     | 
    
         
             
            	$stderr.puts(("! " + e.to_s).color(:red))
         
     | 
    
        data/lib/pickaxe/main.rb
    CHANGED
    
    | 
         @@ -25,7 +25,6 @@ END_OF_TEST 
     | 
|
| 
       25 
25 
     | 
    
         
             
            			@logger.formatter = lambda { |s, t, p, msg| msg.to_s + "\n" }
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            			@questions = @test.shuffled_questions
         
     | 
| 
       28 
     | 
    
         
            -
            			@questions_length = @questions.length.to_f
         
     | 
| 
       29 
28 
     | 
    
         
             
            			@answers = Hash.new([])					
         
     | 
| 
       30 
29 
     | 
    
         
             
            			@started_at = Time.now			
         
     | 
| 
       31 
30 
     | 
    
         
             
            			@current_index = 0
         
     | 
| 
         @@ -35,28 +34,30 @@ END_OF_TEST 
     | 
|
| 
       35 
34 
     | 
    
         
             
            				return
         
     | 
| 
       36 
35 
     | 
    
         
             
            			end
         
     | 
| 
       37 
36 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
            			 
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
            			begin
         
     | 
| 
      
 38 
     | 
    
         
            +
            				puts "! Hit Control-D or Control-C to end test.\n\n".color(:green)	
         
     | 
| 
      
 39 
     | 
    
         
            +
            				while @current_index < @questions.length + (Main.options[:full_test] ? 1 : 0) do
         
     | 
| 
      
 40 
     | 
    
         
            +
            					@question = @questions[@current_index]
         
     | 
| 
       42 
41 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
            					unless @question.nil?
         
     | 
| 
      
 43 
     | 
    
         
            +
            						print "#{@current_index+1} / #{@questions.length}\t\t"
         
     | 
| 
      
 44 
     | 
    
         
            +
            						puts "From: #{@question.file}\t\tTime spent: #{spent?}"
         
     | 
| 
       46 
45 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
            						puts @question.answered(@answers[@question])
         
     | 
| 
      
 47 
     | 
    
         
            +
            					else
         
     | 
| 
      
 48 
     | 
    
         
            +
            						puts END_OF_TEST_MESSAGE
         
     | 
| 
      
 49 
     | 
    
         
            +
            					end
         
     | 
| 
       51 
50 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
            					until (line = prompt?).nil? or command(line)
         
     | 
| 
      
 52 
     | 
    
         
            +
            						# empty
         
     | 
| 
      
 53 
     | 
    
         
            +
            					end															
         
     | 
| 
      
 54 
     | 
    
         
            +
            					break if puts or line.nil?
         
     | 
| 
       54 
55 
     | 
    
         
             
            				end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
            				 
     | 
| 
      
 56 
     | 
    
         
            +
            			rescue Interrupt
         
     | 
| 
      
 57 
     | 
    
         
            +
            				# empty
         
     | 
| 
      
 58 
     | 
    
         
            +
            			ensure						
         
     | 
| 
      
 59 
     | 
    
         
            +
            				statistics!
         
     | 
| 
       57 
60 
     | 
    
         
             
            			end
         
     | 
| 
       58 
     | 
    
         
            -
            			
         
     | 
| 
       59 
     | 
    
         
            -
            			statistics!
         
     | 
| 
       60 
61 
     | 
    
         
             
            		end
         
     | 
| 
       61 
62 
     | 
    
         | 
| 
       62 
63 
     | 
    
         
             
            		#
         
     | 
| 
         @@ -90,7 +91,7 @@ END_OF_TEST 
     | 
|
| 
       90 
91 
     | 
    
         
             
            				if Main.options[:full_test] and @question.nil?
         
     | 
| 
       91 
92 
     | 
    
         
             
            					Main.options[:full_test] = false
         
     | 
| 
       92 
93 
     | 
    
         
             
            					Main.options[:force_show_answers] = true
         
     | 
| 
       93 
     | 
    
         
            -
            					
         
     | 
| 
      
 94 
     | 
    
         
            +
            					@questions_length ||= @questions.length.to_f
         
     | 
| 
       94 
95 
     | 
    
         
             
            					@questions = @test.selected.select { |q| not q.correct?(@answers[q]) }
         
     | 
| 
       95 
96 
     | 
    
         
             
            					@current_index = 0
         
     | 
| 
       96 
97 
     | 
    
         
             
            				else				
         
     | 
| 
         @@ -113,27 +114,41 @@ END_OF_HELP 
     | 
|
| 
       113 
114 
     | 
    
         
             
            				@answers[@question] = line.gsub(/\s+/, "").each_char.collect.to_a.uniq
         
     | 
| 
       114 
115 
     | 
    
         
             
            				unless Main.options[:full_test]
         
     | 
| 
       115 
116 
     | 
    
         
             
            					puts @question.check?(@answers[@question])
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
            					if Main.options[:repeat_incorrect] and not @question.correct?(@answers[@question])
         
     | 
| 
      
 118 
     | 
    
         
            +
            						@answers.delete(@question)
         
     | 
| 
      
 119 
     | 
    
         
            +
            						@questions.insert(@current_index + 1 + rand(@questions.length - @current_index), @question)
         
     | 
| 
      
 120 
     | 
    
         
            +
            						@questions.delete_at(@current_index)						
         
     | 
| 
      
 121 
     | 
    
         
            +
            					else
         
     | 
| 
      
 122 
     | 
    
         
            +
            						@current_index += 1
         
     | 
| 
      
 123 
     | 
    
         
            +
            					end
         
     | 
| 
      
 124 
     | 
    
         
            +
            				else
         
     | 
| 
      
 125 
     | 
    
         
            +
            					@current_index += 1
         
     | 
| 
      
 126 
     | 
    
         
            +
            				end				
         
     | 
| 
       118 
127 
     | 
    
         
             
            				true
         
     | 
| 
       119 
128 
     | 
    
         
             
            			end
         
     | 
| 
       120 
129 
     | 
    
         
             
            		end
         
     | 
| 
       121 
130 
     | 
    
         | 
| 
       122 
131 
     | 
    
         
             
            		def statistics!
         
     | 
| 
       123 
     | 
    
         
            -
            			@ 
     | 
| 
      
 132 
     | 
    
         
            +
            			@questions_length ||= @questions.length.to_f
         
     | 
| 
       124 
133 
     | 
    
         | 
| 
       125 
     | 
    
         
            -
            			@answers.each do |question, answers|
         
     | 
| 
       126 
     | 
    
         
            -
            				@logger << "!" unless question.correct?(answers)
         
     | 
| 
       127 
     | 
    
         
            -
            				@logger << ("#{question.index}: #{answers.join(" ")}\n")
         
     | 
| 
       128 
     | 
    
         
            -
            			end
         
     | 
| 
       129 
     | 
    
         
            -
            			@logger << "\n"
         
     | 
| 
       130 
     | 
    
         
            -
            				
         
     | 
| 
       131 
134 
     | 
    
         
             
            			puts			
         
     | 
| 
       132 
135 
     | 
    
         
             
            			puts "Time: #{spent?}"
         
     | 
| 
       133 
     | 
    
         
            -
            			 
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
      
 136 
     | 
    
         
            +
            			unless Main.options[:repeat_incorrect]
         
     | 
| 
      
 137 
     | 
    
         
            +
            				@stats = @test.statistics!(@answers)
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
            				
         
     | 
| 
      
 140 
     | 
    
         
            +
            				puts "All: #{@questions.length}"
         
     | 
| 
      
 141 
     | 
    
         
            +
            				stat :correct, :green
         
     | 
| 
      
 142 
     | 
    
         
            +
            				stat :unanswered, :yellow
         
     | 
| 
      
 143 
     | 
    
         
            +
            				stat :incorrect, :red
         
     | 
| 
      
 144 
     | 
    
         
            +
            				
         
     | 
| 
      
 145 
     | 
    
         
            +
            				@questions_length ||= @questions.length.to_f
         
     | 
| 
      
 146 
     | 
    
         
            +
            				@answers.each do |question, answers|
         
     | 
| 
      
 147 
     | 
    
         
            +
            					@logger << "!" unless question.correct?(answers)
         
     | 
| 
      
 148 
     | 
    
         
            +
            					@logger << ("#{question.index}: #{answers.join(" ")}\n")
         
     | 
| 
      
 149 
     | 
    
         
            +
            				end
         
     | 
| 
      
 150 
     | 
    
         
            +
            				@logger << "\n"
         
     | 
| 
      
 151 
     | 
    
         
            +
            			end				
         
     | 
| 
       137 
152 
     | 
    
         
             
            		end
         
     | 
| 
       138 
153 
     | 
    
         | 
| 
       139 
154 
     | 
    
         
             
            		def error(msg)
         
     | 
    
        data/lib/pickaxe/test.rb
    CHANGED
    
    | 
         @@ -15,7 +15,7 @@ module Pickaxe 
     | 
|
| 
       15 
15 
     | 
    
         
             
            		include Enumerable
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            		# Ruby-comments and C-comments
         
     | 
| 
       18 
     | 
    
         
            -
            		COMMENTS_RE = /^\s 
     | 
| 
      
 18 
     | 
    
         
            +
            		COMMENTS_RE = /^\s*#.*|^\/\/.*|;.*/
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
            		def initialize(*files)
         
     | 
| 
       21 
21 
     | 
    
         
             
            			@files = files.collect do |file_or_directory|
         
     | 
| 
         @@ -100,7 +100,7 @@ module Pickaxe 
     | 
|
| 
       100 
100 
     | 
    
         
             
            	class Question < Struct.new(:file, :index, :content, :answers)
         
     | 
| 
       101 
101 
     | 
    
         
             
            		include Pickaxe::Errors
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
            		RE = /^\s*(\d+)\.?\s*(.+)$/u
         
     | 
| 
      
 103 
     | 
    
         
            +
            		RE = /^\s*(\d+)\.?\s*(.+)$/u	
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
105 
     | 
    
         
             
            		def self.parse(file, answers)
         
     | 
| 
       106 
106 
     | 
    
         
             
            			content = []
         
     | 
| 
         @@ -180,7 +180,10 @@ module Pickaxe 
     | 
|
| 
       180 
180 
     | 
    
         
             
            			if correct?(given)
         
     | 
| 
       181 
181 
     | 
    
         
             
            				"Correct!".color(:green)
         
     | 
| 
       182 
182 
     | 
    
         
             
            			else
         
     | 
| 
       183 
     | 
    
         
            -
            				 
     | 
| 
      
 183 
     | 
    
         
            +
            				hit = "OK [#{(given & correct_answers).join}]".color(:green)
         
     | 
| 
      
 184 
     | 
    
         
            +
            				missed = "Missed [#{(correct_answers - given).join}]".color(:yellow)				
         
     | 
| 
      
 185 
     | 
    
         
            +
            				incorrect = "Failed [#{(given - correct_answers).join}]".color(:red)				
         
     | 
| 
      
 186 
     | 
    
         
            +
            				"Incorrect, should be: #{correct_answers.join}! #{hit} #{missed} #{incorrect}" 
         
     | 
| 
       184 
187 
     | 
    
         
             
            			end
         
     | 
| 
       185 
188 
     | 
    
         
             
            		end
         
     | 
| 
       186 
189 
     | 
    
         
             
            	end
         
     | 
    
        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: 3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 5
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.5. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 4
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.5.4
         
     | 
| 
       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-12- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2010-12-06 00:00:00 +01:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: bin/pickaxe
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |