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

Commit

Permalink
Enable reek
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei12942 committed Jul 22, 2018
1 parent 6ee0321 commit 4303212
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
6 changes: 2 additions & 4 deletions 2355/2/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions 2355/2/top_words.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4303212

Please sign in to comment.