Module: GamifyingFormatters::Common
- Included in:
- Minitest::GamifyingReporter
- Defined in:
- lib/gamifying_formatter/common.rb
Instance Method Summary collapse
- #calculate_achevements(example_count, failure_count, duration) ⇒ Object
- #decreased_test_time_achievement(old_total_time, new_total_time) ⇒ Object
- #get_trophie(level) ⇒ Object
- #load_test_info ⇒ Object
- #number_of_fixed_tests_achievement(old_failed_tests, new_failed_tests) ⇒ Object
- #number_of_tests_achievement(old_total_tests, new_total_tests) ⇒ Object
- #show_achievements ⇒ Object
- #show_xp_bar ⇒ Object
- #wrap_up(num_of_examples, num_of_failed_examples, duration) ⇒ Object
Instance Method Details
#calculate_achevements(example_count, failure_count, duration) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/gamifying_formatter/common.rb', line 22 def calculate_achevements(example_count, failure_count, duration) achievements = [] achievements << number_of_tests_achievement(@test_info.number_of_tests, example_count) achievements << number_of_fixed_tests_achievement(@test_info.number_of_failed_tests, failure_count) achievements << decreased_test_time_achievement(@test_info.total_time, duration) achievements.delete_if(&:nil?).each { |achievement| @test_info.addAchievement(achievement) } end |
#decreased_test_time_achievement(old_total_time, new_total_time) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/gamifying_formatter/common.rb', line 70 def decreased_test_time_achievement(old_total_time, new_total_time) goal = [100, 50, 25, 10, 5, 1, 0.5, 0.2].select { |target| (old_total_time * 100 - new_total_time * 100).round / 100.0 >= target }.max goal ? "Reduced testing time by #{goal} second(s)!" : nil end |
#get_trophie(level) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/gamifying_formatter/common.rb', line 86 def get_trophie(level) case level when 1 <<-EOS .__. (| |) ( ) _)(_ EOS when 2 <<-EOS {} /__\\ /| |\\ (_| |_) \\ / )( _|__|_ _|______|_ |__________| EOS when 3 <<-EOS ___________ '._==_==_=_.' .-\\: /-. | (|:. |) | '-|:. |-' \\::. / '::. .' ) ( _.' '._ `"""""""`" EOS when 4 <<-EOS .-=========-. \\'-=======-'/ _| .=. |_ ((| {{1}} |)) \\| /|\\ |/ \\__ '`' __/ _`) (`_ _/_______\\_ /___________\\ EOS else '' end end |
#load_test_info ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/gamifying_formatter/common.rb', line 7 def load_test_info if File.exists?('.past_results.yml') @test_info = YAML::load(File.new('.past_results.yml', 'r')) else @test_info = TestInfo.new end end |
#number_of_fixed_tests_achievement(old_failed_tests, new_failed_tests) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/gamifying_formatter/common.rb', line 78 def number_of_fixed_tests_achievement(old_failed_tests, new_failed_tests) goal = [100, 50, 25, 10, 5, 1].select { |target| old_failed_tests - new_failed_tests >= target }.max goal ? "Fixed #{goal} test(s)!" : nil end |
#number_of_tests_achievement(old_total_tests, new_total_tests) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/gamifying_formatter/common.rb', line 62 def number_of_tests_achievement(old_total_tests, new_total_tests) goal = [100, 50, 25, 10, 5, 1].select { |target| new_total_tests - old_total_tests >= target }.max goal ? "Added #{goal} test(s)!" : nil end |
#show_achievements ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gamifying_formatter/common.rb', line 31 def show_achievements output.puts "\n!!!!!!!!Achievements!!!!!!!!" output.puts get_trophie(@test_info.level) output.puts '-' * (@test_info.achievements.uniq.join(" | ").size + 4) output.puts "| #{@test_info.achievements.uniq.join(" | ")} |" output.puts '-' * (@test_info.achievements.uniq.join(" | ").size + 4) end |
#show_xp_bar ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gamifying_formatter/common.rb', line 39 def case @test_info.level when 1 goal_xp = 10 when 2 goal_xp = 25 when 3 goal_xp = 50 when 4 goal_xp = 100 else goal_xp = 1000 end least_common_multiple = goal_xp.lcm(25) numerator = least_common_multiple / goal_xp denominator = least_common_multiple / 25 xp_chars = '=' * ((@test_info.xp * numerator) / denominator).ceil xp_filler = ' ' * (25 - xp_chars.size) output.puts "Level #{@test_info.level}: #{@test_info.xp}/#{goal_xp} [#{xp_chars}#{xp_filler}]" end |
#wrap_up(num_of_examples, num_of_failed_examples, duration) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/gamifying_formatter/common.rb', line 15 def wrap_up(num_of_examples, num_of_failed_examples, duration) @test_info.number_of_tests = num_of_examples @test_info.number_of_failed_tests = num_of_failed_examples @test_info.total_time = duration File.open('.past_results.yml', 'w') { |file| file.puts @test_info.to_yaml } end |