From 4303212493bae29575a1651f00cf4eec3d1c8f9d Mon Sep 17 00:00:00 2001 From: Aleksei Date: Fri, 20 Jul 2018 12:52:46 +0300 Subject: [PATCH] Enable reek --- 2355/2/app.rb | 6 ++---- 2355/2/parser.rb | 51 +++++++++++++++++++++++++-------------------- 2355/2/top_words.rb | 6 ++++++ 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/2355/2/app.rb b/2355/2/app.rb index b57ee743f..a9ca4d395 100644 --- a/2355/2/app.rb +++ b/2355/2/app.rb @@ -4,16 +4,14 @@ OptionParser.new do |opts| opts.on('--top-bad-words=') do |bad| task = Parser.new - task.bad_words = bad task.top_bad_words_values - task.print_table + task.print_table(bad) end opts.on('--top-words=') do |most| task = Parser.new - task.top_words = most opts.on('--name=') do |battler_name| task.name_value(battler_name) - task.name_check + task.name_check(most) end end end.parse! diff --git a/2355/2/parser.rb b/2355/2/parser.rb index 4c062d8d5..8dc748f30 100644 --- a/2355/2/parser.rb +++ b/2355/2/parser.rb @@ -4,15 +4,22 @@ # This class is needed to parsing console params class Parser - attr_reader :bad_words, :top_words, :name - def initialize @top_bad_words = [] @top = TopBad.new + @name = '' + end + + # This method is needed in Parser class, but is doesn't depend on instance state + # This method smells of :reek:UtilityFunction + def bad_words(bad) + !bad.empty? ? bad.to_i : 1 end - def bad_words=(bad) - @bad_words = !bad.empty? ? bad.to_i : 1 + # This method is needed in Parser class, but is doesn't depend on instance state + # This method smells of :reek:UtilityFunction + def top_words(most) + !most.empty? ? most.to_i : 30 end def top_bad_words_values @@ -21,20 +28,14 @@ def top_bad_words_values @top_bad_words = (@top.top_obscenity.sort_by { |_key, val| val }).reverse end - def top_words=(most) - @top_words = !most.empty? ? most.to_i : 30 - end - def name_value(battler_name) @name = battler_name end - def print_top_words + def print_top_words(most) t_w = TopWord.new(@name) - t_w.check_all_words - t_w.pretexts_value - t_w.top_words_counter - t_w.res(top_words) + t_w.ready_top_words + t_w.res(top_words(most)) end def raper @@ -42,14 +43,14 @@ def raper @top.battlers end - def name_check + def name_check(most) if @name.empty? puts 'Choose your destiny!' elsif !raper.include?(@name) puts 'Я не знаю рэпера ' + @name + ', но знаю таких: ' raper.each { |battler| puts battler } else - print_top_words + print_top_words(most) end end @@ -61,15 +62,19 @@ def words_per_round(elem) @top.average_words_in_round(elem).to_s end - def print_table + def table_content(table, bad) + bad_words(bad).times do |index| + value = @top_bad_words[index] + elem = value[0] + table << [elem, value[1].to_s + ' нецензурных слов(а)', + words_per_battle(elem) + ' слов(а) на баттл', + words_per_round(elem) + ' слов(а) в раунде'] + end + end + + def print_table(bad) table = Terminal::Table.new do |tb| - @bad_words.times do |index| - value = @top_bad_words[index] - elem = value[0] - tb << [elem, value[1].to_s + ' нецензурных слов(а)', - words_per_battle(elem) + ' слов(а) на баттл', - words_per_round(elem) + ' слов(а) в раунде'] - end + table_content(tb, bad) end puts table end diff --git a/2355/2/top_words.rb b/2355/2/top_words.rb index 973716e73..6a03591e8 100644 --- a/2355/2/top_words.rb +++ b/2355/2/top_words.rb @@ -52,4 +52,10 @@ def res(value) puts word[0] + ' - ' + word[1].to_s + ' раз(а)' end end + + def ready_top_words + check_all_words + pretexts_value + top_words_counter + end end