-
Notifications
You must be signed in to change notification settings - Fork 43
2355 - 2 #243
base: master
Are you sure you want to change the base?
2355 - 2 #243
Changes from 1 commit
bf43651
e3957b9
b0fa517
c93ee85
ac98a92
6ee0321
4303212
6fc17d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,51 @@ | ||
require 'russian_obscenity' | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Style/IfUnlessModifier | ||
# rubocop:disable Lint/ImplicitStringConcatenation | ||
# rubocop:disable Performance/RedundantMatch | ||
# This class is needed to find and collect all obscenity from text files | ||
# This class smells of :reek:Attribute | ||
# This class smells of :reek:InstanceVariableAssumption | ||
class FindObscenity | ||
attr_accessor :obscenity | ||
attr_reader :obscenity | ||
|
||
def initialize(battler) | ||
@battler = battler | ||
@mistakes = [] | ||
@obscenity = [] | ||
end | ||
|
||
def dir_count | ||
Dir[File.join("./rap-battles/#{@battler}/", '**', '*')].count { |file| File.file?(file) } | ||
end | ||
|
||
def initialize_mistakes | ||
@mistakes = [] | ||
file = File.new('./mistakes') | ||
file.each { |line| @mistakes << line.delete("\n") } | ||
File.new('./mistakes').each { |line| @mistakes << line.delete("\n") } | ||
end | ||
|
||
# This method smells of :reek:DuplicateMethodCall | ||
# This method smells of :reek:NestedIterators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:TooManyStatements | ||
# This method smells of :reek:UncommunicativeVariableName | ||
def check_battles_for_obscenity | ||
initialize_mistakes | ||
@obscenity = [] | ||
1.upto(Dir[File.join("./rap-battles/#{@battler}/", '**', '*')].count { |file| File.file?(file) }) do |i| | ||
file = File.new("./rap-battles/#{@battler}/#{i}") | ||
file.each do |line| | ||
mass = line.split | ||
mass.each do |word| | ||
if word.match(/.*\*.*[А-Яа-я.,]$/) | ||
word = word.delete '.' ',' '?»' '"' '!' ';' | ||
def first_check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix all reek smells. |
||
1.upto(dir_count) do |text| | ||
File.new("./rap-battles/#{@battler}/#{text}").each do |line| | ||
line.split.each do |word| | ||
if word =~ /.*\*.*[А-Яа-я.,]$/ | ||
word = word.delete '.', ',', '?»', '"', '!', ';' | ||
@obscenity << word | ||
end | ||
end | ||
rus_obs = RussianObscenity.find(line) | ||
rus_obs.each do |word| | ||
@mistakes.each do |mis| | ||
if mis.casecmp(word) | ||
rus_obs.delete(word) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# This method smells of :reek:NestedIterators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
def check_rus_obs | ||
1.upto(dir_count) do |text| | ||
File.new("./rap-battles/#{@battler}/#{text}").each do |line| | ||
RussianObscenity.find(line).each do |word| | ||
@mistakes.each { |mis| @obscenity << word unless mis.casecmp(word) } | ||
end | ||
rus_obs.each { |word| @obscenity << word } | ||
end | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/TrailingBlankLines: 1 trailing blank lines detected. |
||
def check_battles_for_obscenity | ||
initialize_mistakes | ||
first_check | ||
check_rus_obs | ||
end | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Metrics/AbcSize | ||
# rubocop:enable Style/IfUnlessModifier | ||
# rubocop:enable Lint/ImplicitStringConcatenation | ||
# rubocop:enable Performance/RedundantMatch |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,53 +3,55 @@ | |
require 'optparse' | ||
require 'terminal-table' | ||
|
||
# rubocop:disable Lint/UnusedBlockArgument | ||
# rubocop:disable Metrics/LineLength | ||
# rubocop:disable Metrics/BlockLength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# rubocop:disable Style/UnneededInterpolation | ||
# rubocop:disable Style/ConditionalAssignment | ||
# rubocop:disable Layout/TrailingWhitespace | ||
# This disable is needed because this block is the main logic of the program. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment means that you just wanted to pass, but not to solve it. Please look through all videos about OOP we had. You should change 'the main logic of the program' |
||
OptionParser.new do |opts| | ||
opts.on('--top-bad-words=') do |bad| | ||
if !bad.empty? | ||
bad_words = bad.to_i | ||
else | ||
bad_words = 1 | ||
end | ||
bad_words = if !bad.empty? | ||
bad.to_i | ||
else | ||
1 | ||
end | ||
top = TopBad.new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't look like OOP. you've just moved all methods to class and calling them. |
||
top.set_battlers_names | ||
top.set_top_obscenity | ||
top_bad_words = top.top_obscenity.sort_by { |key, val| val } | ||
top_bad_words = top.top_obscenity.sort_by { |_key, val| val } | ||
top_bad_words = top_bad_words.reverse | ||
table = Terminal::Table.new do |t| | ||
(bad_words - 1).times do |i| | ||
t << ["#{top_bad_words[i][0]}", "#{top_bad_words[i][1]}" + ' нецензурных слов(а)', "#{top.average_bad_words_in_battle("#{top_bad_words[i][0]}")}" + ' слов(а) на баттл', "#{top.average_words_in_round("#{top_bad_words[i][0]}")}" + ' слов(а) в раунде'] | ||
t << [top_bad_words[i][0], | ||
top_bad_words[i][1].to_s + ' нецензурных слов(а)', | ||
top.average_bad_words_in_battle(top_bad_words[i][0]).to_s + ' слов(а) на баттл', | ||
top.average_words_in_round(top_bad_words[i][0]).to_s + ' слов(а) в раунде'] | ||
t << :separator | ||
end | ||
i = bad_words - 1 | ||
t << ["#{top_bad_words[i][0]}", "#{top_bad_words[i][1]}" + ' нецензурных слов(а)', "#{top.average_bad_words_in_battle("#{top_bad_words[i][0]}")}" + ' слов(а) на баттл', "#{top.average_words_in_round("#{top_bad_words[i][0]}")}" + ' слов(а) в раунде'] | ||
t << [top_bad_words[i][0], | ||
top_bad_words[i][1].to_s + ' нецензурных слов(а)', | ||
top.average_bad_words_in_battle(top_bad_words[i][0]).to_s + ' слов(а) на баттл', | ||
top.average_words_in_round(top_bad_words[i][0]).to_s + ' слов(а) в раунде'] | ||
end | ||
puts table | ||
end | ||
|
||
opts.on('--top-words=') do |top_w| | ||
if !top_w.empty? | ||
top_words = top_w.to_i | ||
else | ||
top_words = 30 | ||
end | ||
top_words = if !top_w.empty? | ||
top_w.to_i | ||
else | ||
30 | ||
end | ||
opts.on('--name=') do |b_name| | ||
if b_name.empty? | ||
if b_name.empty? | ||
puts 'Choose your destiny!' | ||
else | ||
name_b = b_name | ||
top = TopBad.new | ||
top.set_battlers_names | ||
if top.battlers.index("#{name_b}").nil? | ||
puts 'Я не знаю рэпера ' + "#{name_b}" + ', но знаю таких: ' | ||
top.battlers.each { |battl| puts battl } | ||
if !top.battlers.include?(name_b) | ||
puts 'Я не знаю рэпера ' + name_b + ', но знаю таких: ' | ||
top.battlers.each { |battler| puts battler } | ||
else | ||
t_w = TopWord.new("#{name_b}") | ||
t_w = TopWord.new(name_b) | ||
t_w.check_all_words | ||
t_w.top_words_counter | ||
t_w.res(top_words) | ||
|
@@ -58,9 +60,4 @@ | |
end | ||
end | ||
end.parse! | ||
# rubocop:enable Lint/UnusedBlockArgument | ||
# rubocop:enable Metrics/LineLength | ||
# rubocop:enable Metrics/BlockLength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# rubocop:enable Style/UnneededInterpolation | ||
# rubocop:enable Style/ConditionalAssignment | ||
# rubocop:enable Layout/TrailingWhitespace |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
require './find_obscenity.rb' | ||
|
||
# rubocop:disable Lint/Syntax | ||
# This class is needed for first level of Task 2 | ||
# This class smells of :reek:Attribute | ||
class TopBad | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: class definition in method body There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax: This file has class definition in method body. More info. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: class definition in method body There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax: This file has class definition in method body. More info. |
||
attr_accessor :battlers, :top_obscenity | ||
attr_reader :battlers, :top_obscenity | ||
|
||
def initialize | ||
@battlers = [] | ||
|
@@ -16,33 +14,32 @@ def set_battlers_names | |
file.each { |line| @battlers << line.delete("\n") } | ||
end | ||
|
||
# This method smells of :reek:UtilityFunction | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
def dir_count(battler) | ||
Dir[File.join("./rap-battles/#{battler}/", '**', '*')].count { |file| File.file?(file) } | ||
end | ||
|
||
# This method smells of :reek:DuplicateMethodCall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
def set_top_obscenity | ||
0.upto(battlers.size - 1) do |index | ||
check = FindObscenity.new(@battlers[indexx]) | ||
0.upto(battlers.size - 1) do |index| | ||
check = FindObscenity.new(@battlers[index]) | ||
check.check_battles_for_obscenity | ||
top_obscenity["#{@battlers[indexx]}"] = check.obscenity.size | ||
top_obscenity[@battlers[index]] = check.obscenity.size | ||
end | ||
end | ||
|
||
# This method smells of :reek:DuplicateMethodCall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:NestedIterators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:TooManyStatements | ||
# This method smells of :reek:UtilityFunction | ||
def average_words_in_round(battler) | ||
counter = 0 | ||
1.upto(Dir[File.join("./rap-battles/#{battler}/", '**', '*')].count { |file| File.file?(file) }) do |indexx| | ||
file = File.new("./rap-battles/#{battler}/#{indexx}") | ||
file.each do |line| | ||
mass = line.split | ||
mass.each { counter += 1 } | ||
def average_words_in_round(battler, counter = 0) | ||
1.upto(dir_count(battler)) do |text| | ||
File.new("./rap-battles/#{battler}/#{text}").each do |line| | ||
line.split.each { counter += 1 } | ||
end | ||
end | ||
counter / ((Dir[File.join("./rap-battles/#{battler}/", '**', '*')].count { |file| File.file?(file) }) * 3) | ||
counter / (dir_count(battler) * 3) | ||
end | ||
|
||
def average_bad_words_in_battle(battler) | ||
top_obscenity["#{battler}"] / (Dir[File.join("./rap-battles/#{battler}/", '**', '*')].count { |file| File.file?(file) }) | ||
end | ||
top_obscenity[battler] / dir_count(battler) | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: unexpected token kEND There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax: This file has unexpected token kEND. More info. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/Syntax: unexpected token kEND There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Syntax: This file has unexpected token kEND. More info. |
||
# rubocop:enable Lint/Syntax |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,46 @@ | ||
# rubocop:disable Metrics/AbcSize | ||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Style/UnneededInterpolation | ||
# rubocop:disable Style/IfUnlessModifier | ||
# rubocop:disable Style/NegatedWhile | ||
# rubocop:disable Lint/UnusedBlockArgument | ||
# rubocop:disable Lint/ImplicitStringConcatenation | ||
# This class is needed to find most popular words from text files | ||
# This class smells of :reek:Attribute | ||
class TopWord | ||
attr_accessor :battler | ||
attr_reader :battler | ||
|
||
def initialize(battler) | ||
@battler = battler | ||
@words = [] | ||
@top_words = {} | ||
end | ||
|
||
def dir_count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have code duplication between two classes. |
||
Dir[File.join("./rap-battles/#{@battler}/", '**', '*')].count { |file| File.file?(file) } | ||
end | ||
|
||
# This method smells of :reek:NestedIterators | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:TooManyStatements | ||
# This method smells of :reek:UncommunicativeVariableName | ||
def check_all_words | ||
1.upto(Dir[File.join("./rap-battles/#{@battler}/", '**', '*')].count { |file| File.file?(file) }) do |i| | ||
file = File.new("./rap-battles/#{@battler}/#{i}") | ||
file.each do |line| | ||
mass = line.split | ||
mass.each do |word| | ||
word = word.delete '.' ',' '?»' '"' '!' ';' | ||
1.upto(dir_count) do |text| | ||
File.new("./rap-battles/#{@battler}/#{text}").each do |line| | ||
line.split.each do |word| | ||
word = word.delete '.', ',', '?»', '"', '!', ';' | ||
@words << word | ||
end | ||
end | ||
end | ||
end | ||
|
||
# This method smells of :reek:DuplicateMethodCall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:NilCheck | ||
# This method smells of :reek:TooManyStatements | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
def top_words_counter | ||
mistakes = [] | ||
file = File.new('./pretexts') | ||
file.each { |line| mistakes << line.delete("\n") } | ||
while !@words.empty? | ||
pretexts = [] | ||
File.new('./pretexts').each { |line| pretexts << line.delete("\n") } | ||
while @words.any? | ||
counter = 0 | ||
@words.each do |word| | ||
if word == @words[0] && mistakes.index(word).nil? | ||
counter += 1 | ||
end | ||
end | ||
@top_words["#{@words[0]}"] = counter | ||
@words.delete("#{@words[0]}") | ||
@words.each { |word| counter += 1 if word == @words[0] && !pretexts.include?(word) } | ||
@top_words[@words[0]] = counter | ||
@words.delete(@words[0]) | ||
end | ||
end | ||
|
||
# This method smells of :reek:DuplicateMethodCall | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wtf? |
||
# This method smells of :reek:TooManyStatements | ||
# This method smells of :reek:UncommunicativeVariableName | ||
def res(value) | ||
res = [] | ||
@top_words = @top_words.sort_by { |key, val| val } | ||
@top_words = @top_words.sort_by { |_key, val| val } | ||
@top_words = @top_words.reverse | ||
0.upto(value - 1) { |i| res << @top_words[i] } | ||
res.size.times { |i| puts "#{res[i][0]}" + ' - ' + "#{res[i][1]}" + ' раз(а)' } | ||
0.upto(value - 1) { |index| puts @top_words[index][0] + ' - ' + @top_words[index][1].to_s + ' раз(а)' } | ||
end | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Style/UnneededInterpolation | ||
# rubocop:enable Style/IfUnlessModifier | ||
# rubocop:enable Style/NegatedWhile | ||
# rubocop:enable Lint/UnusedBlockArgument | ||
# rubocop:enable Lint/ImplicitStringConcatenation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't name classes with verbs.