This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable rubocop and rework project's structure
- Loading branch information
1 parent
ac98a92
commit 6ee0321
Showing
7 changed files
with
152 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require './parser.rb' | ||
require 'optparse' | ||
|
||
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 | ||
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 | ||
end | ||
end | ||
end.parse! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require './top_bad_words.rb' | ||
require './top_words.rb' | ||
require 'terminal-table' | ||
|
||
# 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 | ||
end | ||
|
||
def bad_words=(bad) | ||
@bad_words = !bad.empty? ? bad.to_i : 1 | ||
end | ||
|
||
def top_bad_words_values | ||
@top.battlers_names | ||
@top.top_obscenity_check | ||
@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 | ||
t_w = TopWord.new(@name) | ||
t_w.check_all_words | ||
t_w.pretexts_value | ||
t_w.top_words_counter | ||
t_w.res(top_words) | ||
end | ||
|
||
def raper | ||
@top.battlers_names | ||
@top.battlers | ||
end | ||
|
||
def name_check | ||
if @name.empty? | ||
puts 'Choose your destiny!' | ||
elsif !raper.include?(@name) | ||
puts 'Я не знаю рэпера ' + @name + ', но знаю таких: ' | ||
raper.each { |battler| puts battler } | ||
else | ||
print_top_words | ||
end | ||
end | ||
|
||
def words_per_battle(elem) | ||
@top.average_bad_words_in_battle(elem).to_s | ||
end | ||
|
||
def words_per_round(elem) | ||
@top.average_words_in_round(elem).to_s | ||
end | ||
|
||
def print_table | ||
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 | ||
end | ||
puts table | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters