Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mihail Sokurenko-0 #26

Open
wants to merge 4 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
148 changes: 148 additions & 0 deletions Mihail Sokurenko/0/hw0.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
require 'roo'
require 'roo-xls'

class Price

Choose a reason for hiding this comment

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

Metrics/ClassLength: Class has too many lines. [121/100]

Choose a reason for hiding this comment

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

Metrics/ClassLength: Class has too many lines. [117/100]

def initialize
@c = Roo::Excelx.new('./date/Average_prices(serv)-10-2018.xlsx')
puts 'What price are u looking for?'
@name = gets.chomp
@pr = 0
@all = []
@date = { 'январь': '01', 'февраль': '02', 'март': '03', 'апрель': '04',
'май': '05', 'июнь': '06', 'июль': '07', 'август': '08',
'сентябрь': '09', 'октябрь': '10', 'ноябрь': '11',
'декабрь': '12'}
end

def find

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for find is too high. [16.31/15]
Metrics/MethodLength: Method has too many lines. [12/10]

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for find is too high. [17.23/15]

@k = 0
@l = 0
@c.each_with_index do |mas, i|
mas.each_with_index do |arr, j|
if mas[0] != nil && mas[0] == @name.upcase || mas[0] =~ /#{@name.upcase}[.,) ]{1}/

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Style/NonNilCheck: Prefer !expression.nil? over expression != nil.

@l = i + 1
end
if arr == 'г. Минск'
@k = j
end
@pr = @c.row(@l)[@k]
end
end
out()
end

def min

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for min is too high. [28.3/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for min is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [17/10]

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for min is too high. [27.35/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for min is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [17/10]

min = @pr
all_files
@all.each do |f|
if !f.nil?

Choose a reason for hiding this comment

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

Style/NegatedIf: Favor unless over if for negative conditions.
Style/Next: Use next to skip iteration.

dat = get_date(f)
old_price(f) ? coef = 0.0001 : coef = 1

Choose a reason for hiding this comment

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

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.

f.each_with_index do |_, i|
if f.row(i)[0] == @name.upcase || f.row(i)[0] =~ /#{@name.upcase}[.,) ]{1}/
if !f.row(i)[@k].nil? && (coef * f.row(i)[@k]) < min
min=coef * f.row(i)[@k]
@min_dat = dat
end
end
end
end
end
min_out(min, @min_dat)
end

def max

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for max is too high. [28.3/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for max is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [17/10]

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for max is too high. [27.35/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for max is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [17/10]

max = @pr
all_files
@all.each do |f|
if !f.nil?

Choose a reason for hiding this comment

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

Style/NegatedIf: Favor unless over if for negative conditions.
Style/Next: Use next to skip iteration.

dat = get_date(f)
old_price(f) ? coef = 0.0001 : coef = 1

Choose a reason for hiding this comment

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

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.

f.each_with_index do |_, i|
if f.row(i)[0] == @name.upcase || f.row(i)[0] =~ /#{@name.upcase}[.,) ]{1}/
if !f.row(i)[@k].nil? && (coef * f.row(i)[@k]) > max
max=coef * f.row(i)[@k]
@max_dat = dat
end
end
end
end
end
max_out(max, @max_dat)
end

def similar

Choose a reason for hiding this comment

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

Metrics/AbcSize: Assignment Branch Condition size for similar is too high. [15.65/15]

a = []
@c.each do |mas|
mas.each do |arr|
if arr == @pr && mas[0] !~ /#{@name.upcase}[.,) ]{1}/ && mas[0] != @name.upcase && !arr.nil?

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.

a << mas[0]
end
end
end
a = a.uniq
similar_out(a)
end

def get_date(file)
dates = file.row(3)[0].split(' ')
@date.each do |d, t|
if dates[1] == d.to_s

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.

dates[1] = t
end
end
dates[1..2]
end

def old_price(file)
date = get_date(file)
if date[1].to_i < 2017

Choose a reason for hiding this comment

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

Style/GuardClause: Use a guard clause instead of wrapping the code inside a conditional expression.
Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.

true
end
end

def all_files
Dir.foreach('./date').each do |file|
case File.extname(file)
when '.xlsx' then

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

@all << Roo::Excelx.new("./date/#{file}")
when '.xls' then
@all << Roo::Excel.new("./date/#{file}")
end
end
@all
end

def out()

Choose a reason for hiding this comment

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

Style/DefWithParentheses: Omit the parentheses in defs when the method doesn't accept any arguments.

if @pr.nil? && @l.zero?
puts "No #{@name} in table"
else
puts"'#{@name.capitalize}' is #{@pr} BYN in Minsk in these days"

Choose a reason for hiding this comment

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

Layout/SpaceBeforeFirstArg: Put one space between the method name and the first argument.

min()

Choose a reason for hiding this comment

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

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.

max()

Choose a reason for hiding this comment

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

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.

similar()

Choose a reason for hiding this comment

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

Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.

end
end

def min_out(min_v, min_dat)
puts"Lowest price was on #{min_dat[0]}/#{min_dat[1]} at #{min_v} BYN"
end

def max_out(max_v, max_dat)
puts"Highest price was on #{max_dat[0]}/#{max_dat[1]} at #{max_v} BYN"
end

def similar_out(a)

Choose a reason for hiding this comment

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

Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.

if a.empty?
puts"No product with similar price"

Choose a reason for hiding this comment

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

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

else

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

str = a.map{|r| "#{r.capitalize.gsub(/\s+/, " ").gsub(/\n/, " ")}"}.join(', ')

Choose a reason for hiding this comment

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

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
Performance/StringReplacement: Use tr instead of gsub.
Layout/SpaceInsideBlockBraces: Space missing inside }.
Layout/TrailingWhitespace: Trailing whitespace detected.

puts "For similar price u can buy #{str}"

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

end
end

Choose a reason for hiding this comment

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

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end.

end

s = Price.new
s.find

Choose a reason for hiding this comment

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

Layout/TrailingBlankLines: 1 trailing blank lines detected.