Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

2355 - 2 #243

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable reek
Aleksei12942 committed Jul 22, 2018
commit 4303212493bae29575a1651f00cf4eec3d1c8f9d
6 changes: 2 additions & 4 deletions 2355/2/app.rb
Original file line number Diff line number Diff line change
@@ -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!
51 changes: 28 additions & 23 deletions 2355/2/parser.rb
Original file line number Diff line number Diff line change
@@ -4,15 +4,22 @@

# This class is needed to parsing console params
class Parser

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InstanceVariableAssumption: Parser assumes too much for instance variable '@bad_words'. More info.
InstanceVariableAssumption: Parser assumes too much for instance variable '@name'. More info.
TooManyInstanceVariables: Parser has at least 5 instance variables. More info.

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,35 +28,29 @@ 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
@top.battlers_names
@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
6 changes: 6 additions & 0 deletions 2355/2/top_words.rb
Original file line number Diff line number Diff line change
@@ -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