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 reek were it is possible
- Loading branch information
1 parent
5ac20ee
commit 68912cb
Showing
4 changed files
with
88 additions
and
126 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
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 | ||
# 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 | ||
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 | ||
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 | ||
|
||
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 |
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
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 |
---|---|---|
@@ -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 | ||
Dir[File.join("./rap-battles/#{@battler}/", '**', '*')].count { |file| File.file?(file) } | ||
end | ||
|
||
# This method smells of :reek:NestedIterators | ||
# 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 | ||
# This method smells of :reek:NilCheck | ||
# This method smells of :reek:TooManyStatements | ||
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 | ||
# 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 |