-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,148 @@ | ||
require 'roo' | ||
require 'roo-xls' | ||
|
||
class Price | ||
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. 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 | ||
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. Metrics/AbcSize: Assignment Branch Condition size for find is too high. [16.31/15] 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. 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}/ | ||
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. Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. |
||
@l = i + 1 | ||
end | ||
if arr == 'г. Минск' | ||
@k = j | ||
end | ||
@pr = @c.row(@l)[@k] | ||
end | ||
end | ||
out() | ||
end | ||
|
||
def min | ||
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. Metrics/AbcSize: Assignment Branch Condition size for min is too high. [28.3/15] 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. Metrics/AbcSize: Assignment Branch Condition size for min is too high. [27.35/15] |
||
min = @pr | ||
all_files | ||
@all.each do |f| | ||
if !f.nil? | ||
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. Style/NegatedIf: Favor unless over if for negative conditions. |
||
dat = get_date(f) | ||
old_price(f) ? coef = 0.0001 : coef = 1 | ||
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. 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 | ||
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. Metrics/AbcSize: Assignment Branch Condition size for max is too high. [28.3/15] 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. Metrics/AbcSize: Assignment Branch Condition size for max is too high. [27.35/15] |
||
max = @pr | ||
all_files | ||
@all.each do |f| | ||
if !f.nil? | ||
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. Style/NegatedIf: Favor unless over if for negative conditions. |
||
dat = get_date(f) | ||
old_price(f) ? coef = 0.0001 : coef = 1 | ||
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. 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 | ||
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. 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? | ||
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. 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 | ||
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. 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 | ||
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. Style/GuardClause: Use a guard clause instead of wrapping the code inside a conditional expression. |
||
true | ||
end | ||
end | ||
|
||
def all_files | ||
Dir.foreach('./date').each do |file| | ||
case File.extname(file) | ||
when '.xlsx' then | ||
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/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() | ||
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. 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" | ||
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/SpaceBeforeFirstArg: Put one space between the method name and the first argument. |
||
min() | ||
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. Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments. |
||
max() | ||
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. Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments. |
||
similar() | ||
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. 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) | ||
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. Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long. |
||
if a.empty? | ||
puts"No product with similar price" | ||
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. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
else | ||
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/TrailingWhitespace: Trailing whitespace detected. |
||
str = a.map{|r| "#{r.capitalize.gsub(/\s+/, " ").gsub(/\n/, " ")}"}.join(', ') | ||
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/SpaceBeforeBlockBraces: Space missing to the left of {. |
||
puts "For similar price u can buy #{str}" | ||
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/TrailingWhitespace: Trailing whitespace detected. |
||
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/EmptyLinesAroundClassBody: Extra empty line detected at class body end. |
||
end | ||
|
||
s = Price.new | ||
s.find | ||
|
||
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. |
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.
Metrics/ClassLength: Class has too many lines. [121/100]