-
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
Kirill Hryvicki - 0 #20
base: master
Are you sure you want to change the base?
Conversation
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
end | ||
|
||
main() |
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.
Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.
Layout/TrailingBlankLines: Final newline missing.
Hryvicki Kirill/0/run.rb
Outdated
puts "For similar price you also can afford" | ||
puts similarProducts | ||
end | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
if similarProducts.length == 0 | ||
puts "No products for similar price" | ||
else | ||
puts "For similar price you also can afford" |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
similarProducts = getSimilarPriceProducts(recentPriceData, products) | ||
|
||
if similarProducts.length == 0 | ||
puts "No products for similar price" |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
|
||
similarProducts = getSimilarPriceProducts(recentPriceData, products) | ||
|
||
if similarProducts.length == 0 |
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.
Style/NumericPredicate: Use similarProducts.length.zero? instead of similarProducts.length == 0.
Style/ZeroLengthPredicate: Use empty? instead of length == 0.
Hryvicki Kirill/0/run.rb
Outdated
puts "" | ||
recentPriceData = getRecentPriceData(key, products, monthMap) | ||
puts key.capitalize + " is " + recentPriceData["price"].to_s + " BYN in Minsk these days." | ||
minPrice = getMinPrice(products[key]) |
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.
Naming/VariableName: Use snake_case for variable names.
Hryvicki Kirill/0/run.rb
Outdated
keys.each{|key| | ||
puts "" | ||
recentPriceData = getRecentPriceData(key, products, monthMap) | ||
puts key.capitalize + " is " + recentPriceData["price"].to_s + " BYN in Minsk these days." |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
else | ||
keys.each{|key| | ||
puts "" | ||
recentPriceData = getRecentPriceData(key, products, monthMap) |
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.
Naming/VariableName: Use snake_case for variable names.
Hryvicki Kirill/0/run.rb
Outdated
puts word.capitalize + " can not be found in database" | ||
else | ||
keys.each{|key| | ||
puts "" |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
if keys.length == 0 | ||
puts word.capitalize + " can not be found in database" | ||
else | ||
keys.each{|key| |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
small fixes
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
puts "For similar price you also can afford" | ||
puts similarProducts | ||
end | ||
} |
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.
Layout/BlockAlignment: } at 236, 8 is not aligned with keys.each { |key| at 222, 6.
Hryvicki Kirill/0/run.rb
Outdated
if similarProducts.empty? == 0 | ||
puts "No products for similar price" | ||
else | ||
puts "For similar price you also can afford" |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
puts "Maximum was on " + maxPrice["year"] + "/" + monthMap[maxPrice["month"]].to_s + " at price " + maxPrice["price"].to_s + " BYN" | ||
similarProducts = getSimilarPriceProducts(recentPriceData, products) | ||
if similarProducts.empty? == 0 | ||
puts "No products for similar price" |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
maxPrice = getMaxPrice(products[key]) | ||
puts "Maximum was on " + maxPrice["year"] + "/" + monthMap[maxPrice["month"]].to_s + " at price " + maxPrice["price"].to_s + " BYN" | ||
similarProducts = getSimilarPriceProducts(recentPriceData, products) | ||
if similarProducts.empty? == 0 |
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.
Style/NumericPredicate: Use similarProducts.empty?.zero? instead of similarProducts.empty? == 0.
Hryvicki Kirill/0/run.rb
Outdated
puts "Lowest was on " + minPrice["year"] + "/" + monthMap[minPrice["month"]].to_s + " at price " + minPrice["price"].to_s + " BYN" | ||
maxPrice = getMaxPrice(products[key]) | ||
puts "Maximum was on " + maxPrice["year"] + "/" + monthMap[maxPrice["month"]].to_s + " at price " + maxPrice["price"].to_s + " BYN" | ||
similarProducts = getSimilarPriceProducts(recentPriceData, products) |
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.
Naming/VariableName: Use snake_case for variable names.
Hryvicki Kirill/0/run.rb
Outdated
if keys.length == 0 | ||
puts word.capitalize + " can not be found in database" | ||
else | ||
keys.each { |key| |
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.
Style/BlockDelimiters: Avoid using {...} for multi-line blocks.
Hryvicki Kirill/0/run.rb
Outdated
word = gets.chomp.downcase | ||
keys = findKeys(word, products) | ||
if keys.length == 0 | ||
puts word.capitalize + " can not be found in database" |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
puts "What price are you looking for?" | ||
word = gets.chomp.downcase | ||
keys = findKeys(word, products) | ||
if keys.length == 0 |
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.
Style/NumericPredicate: Use keys.length.zero? instead of keys.length == 0.
Style/ZeroLengthPredicate: Use empty? instead of length == 0.
Hryvicki Kirill/0/run.rb
Outdated
} | ||
|
||
while true | ||
puts "What price are you looking for?" |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
} | ||
|
||
while true |
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.
Style/InfiniteLoop: Use Kernel#loop for infinite loops.
Lint/LiteralAsCondition: Literal true appeared as a condition.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
|
||
max_price = getMaxPrice(products[key]) | ||
puts 'Maximum was on ' + max_price["year"] + '/' + month_map[max_price["month"]].to_s + | ||
' at price ' + max_price["price"].to_s + ' BYN' |
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.
Layout/MultilineOperationIndentation: Align the operands of an expression spanning multiple lines.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
|
||
min_price = getMinPrice(products[key]) | ||
puts 'Lowest was on ' + min_price["year"] + '/' + month_map[min_price["month"]].to_s + | ||
' at price ' + min_price["price"].to_s + ' BYN' |
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.
Layout/MultilineOperationIndentation: Align the operands of an expression spanning multiple lines.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
puts key.capitalize + ' is ' + recent_price_data["price"].to_s + ' BYN in Minsk these days.' | ||
|
||
min_price = getMinPrice(products[key]) | ||
puts 'Lowest was on ' + min_price["year"] + '/' + month_map[min_price["month"]].to_s + |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
keys.each { |key| | ||
recent_price_data = getRecentPriceData(key, products, month_map) | ||
puts '' | ||
puts key.capitalize + ' is ' + recent_price_data["price"].to_s + ' BYN in Minsk these days.' |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
|
||
loop do | ||
puts 'What price are you looking for?' | ||
word = gets.chomp.downcase #.encode("UTF-8") |
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.
Layout/ExtraSpacing: Unnecessary spacing detected.
Layout/LeadingCommentSpace: Missing space after #.
Hryvicki Kirill/0/run.rb
Outdated
'ноябрь' => 11, | ||
'декабрь' => 12, | ||
} | ||
|
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
'сентябрь' => 9, | ||
'октябрь' => 10, | ||
'ноябрь' => 11, | ||
'декабрь' => 12, |
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.
Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
Hryvicki Kirill/0/run.rb
Outdated
return result | ||
end | ||
|
||
def main |
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/AbcSize: Assignment Branch Condition size for main is too high. [61.07/15]
Metrics/MethodLength: Method has too many lines. [50/10]
Hryvicki Kirill/0/run.rb
Outdated
result.push(product) | ||
end | ||
} | ||
return result |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
if !product_data[year][month] | ||
next | ||
end | ||
if product_data[year][month]["Minsk"] == price && product != origin_product |
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.
Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
|
||
max_price = getMaxPrice(products[key]) | ||
puts 'Maximum was on ' + max_price['year'] + '/' + month_map[max_price['month']].to_s + | ||
' at price ' + max_price['price'].to_s + ' BYN' |
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.
Layout/MultilineOperationIndentation: Align the operands of an expression spanning multiple lines.
Hryvicki Kirill/0/run.rb
Outdated
|
||
min_price = getMinPrice(products[key]) | ||
puts 'Lowest was on ' + min_price['year'] + '/' + month_map[min_price['month']].to_s + | ||
' at price ' + min_price['price'].to_s + ' BYN' |
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.
Layout/MultilineOperationIndentation: Align the operands of an expression spanning multiple lines.
Hryvicki Kirill/0/run.rb
Outdated
|
||
file_paths.each do |file_path| | ||
file_instance = getFileInstance(file_path) | ||
fetchProductsData(file_instance, products, regions) if file_instance |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
return result | ||
end | ||
|
||
def main |
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/AbcSize: Assignment Branch Condition size for main is too high. [60.09/15]
Metrics/MethodLength: Method has too many lines. [48/10]
Hryvicki Kirill/0/run.rb
Outdated
|
||
products.each { |product, product_data| | ||
next if !product_data[year] | ||
next if !product_data[year][month] |
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.
Style/NegatedIf: Favor unless over if for negative conditions.
Hryvicki Kirill/0/run.rb
Outdated
return result | ||
end | ||
|
||
def getMaxPrice(hash) |
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/MethodLength: Method has too many lines. [19/10]
Naming/MethodName: Use snake_case for method names.
Hryvicki Kirill/0/run.rb
Outdated
result['price'] = min_year_price | ||
end | ||
end | ||
return result |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
result['month'] = month | ||
end | ||
end | ||
if min_month_price < min_year_price |
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.
Style/Next: Use next to skip iteration.
Hryvicki Kirill/0/run.rb
Outdated
min_month_price = 9999999999999 | ||
year_hash.each do |month, month_hash| | ||
price = month_hash['Minsk'] | ||
next if !price |
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.
Style/NegatedIf: Favor unless over if for negative conditions.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
min_year_price = 9999999999999 | ||
|
||
hash.each do |year, year_hash| | ||
min_month_price = 9999999999999 |
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.
Style/NumericLiterals: Use underscores(_) as decimal mark and separate every 3 digits with them.
fix4
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def getMinPrice(hash) | ||
result = {} | ||
min_year_price = 9999999999999 |
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.
Style/NumericLiterals: Use underscores(_) as decimal mark and separate every 3 digits with them.
Hryvicki Kirill/0/run.rb
Outdated
} | ||
end | ||
|
||
def getMinPrice(hash) |
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/MethodLength: Method has too many lines. [19/10]
Naming/MethodName: Use snake_case for method names.
Hryvicki Kirill/0/run.rb
Outdated
'year' => year_key, | ||
'month' => month_key, | ||
'product' => key | ||
} |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
month_key = product_month_data.keys.max{ |a,b| month_map[a].to_i <=> month_map[b].to_i} | ||
end | ||
|
||
return { |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
if product_month_data[current_month] | ||
month_key = current_month | ||
else | ||
month_key = product_month_data.keys.max{ |a,b| month_map[a].to_i <=> month_map[b].to_i} |
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.
Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceAfterComma: Space missing after comma.
Layout/SpaceInsideBlockBraces: Space missing inside }.
Hryvicki Kirill/0/run.rb
Outdated
if val | ||
result = val.to_f | ||
result = result / 10000 if year.to_i < 2017 | ||
return result.round(2) |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
def formatValue(val, year) | ||
if val | ||
result = val.to_f | ||
result = result / 10000 if year.to_i < 2017 |
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.
Style/SelfAssignment: Use self-assignment shorthand /=.
Style/NumericLiterals: Use underscores(_) as decimal mark and separate every 3 digits with them.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def formatValue(val, year) | ||
if val |
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.
Style/GuardClause: Use a guard clause instead of wrapping the code inside a conditional expression.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
end | ||
|
||
def formatValue(val, year) |
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.
Naming/MethodName: Use snake_case for method names.
Hryvicki Kirill/0/run.rb
Outdated
key = file_instance.cell('A', n).strip.downcase | ||
|
||
products[key] = {} if !products[key] | ||
products[key][year] = {} if !products[key][year] |
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.
Style/NegatedIf: Favor unless over if for negative conditions.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
month = file_instance.cell('A', 3).split(' ')[1] | ||
key = file_instance.cell('A', n).strip.downcase | ||
|
||
products[key] = {} if !products[key] |
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.
Style/NegatedIf: Favor unless over if for negative conditions.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def fetchProductsData(file_instance, products, regions) | ||
for n in 9..file_instance.last_row | ||
next if file_instance.cell('E', n) == nil |
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.
Style/NilComparison: Prefer the use of the nil? predicate.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def fetchProductsData(file_instance, products, regions) | ||
for n in 9..file_instance.last_row |
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.
Style/For: Prefer each over for.
Hryvicki Kirill/0/run.rb
Outdated
return result | ||
end | ||
|
||
def fetchProductsData(file_instance, products, regions) |
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/AbcSize: Assignment Branch Condition size for fetchProductsData is too high. [41.79/15]
Metrics/MethodLength: Method has too many lines. [17/10]
Naming/MethodName: Use snake_case for method names.
Hryvicki Kirill/0/run.rb
Outdated
products.keys.each { |key| | ||
result.push(key) if(key.include?(word)) | ||
} | ||
return result |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
require 'roo' | ||
require 'roo-xls' | ||
|
||
def getFileInstance(file_path) |
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/MethodLength: Method has too many lines. [14/10]
Naming/MethodName: Use snake_case for method names.
Hryvicki Kirill/0/rub.rb
Outdated
end | ||
end | ||
end | ||
end |
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.
Lint/Syntax: unexpected token kEND
Hryvicki Kirill/0/rub.rb
Outdated
puts key.capitalize+' is '+recent_price_data['price'].to_s+' BYN in Minsk these days.' | ||
|
||
min_price = get_min_price(products[key]) | ||
puts 'Lowest was on '+min_price['year']+'/'+month_map[min_price['month']].to_s +' at price '+min_price['price'].to_s+' BYN' |
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.
Lint/Syntax: +' interpreted as argument prefix
Hryvicki Kirill/0/loadFiles.rb
Outdated
end | ||
download = open(f_link) | ||
IO.copy_stream(download, "./data/#{download.base_uri.to_s.split('/')[-1]}") | ||
end |
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.
Layout/TrailingBlankLines: Final newline missing.
Hryvicki Kirill/0/loadFiles.rb
Outdated
else | ||
f_link = 'http://www.belstat.gov.by' + str_link | ||
end | ||
download = open(f_link) |
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.
Security/Open: The use of Kernel#open is a serious security risk.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
min_price = get_min_price(products[key]) | ||
puts 'Lowest was on '+min_price['year']+'/'+month_map[min_price['month']].to_s+' at price '+min_price['price'].to_s+' BYN' | ||
max_price = get_max_price(products[key]) | ||
puts 'Maximum was on '+max_price['year']+'/'+month_map[max_price['month']].to_s+' at price '+max_price['price'].to_s+' BYN' |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator +.
Metrics/LineLength: Line is too long. [129/120]
Hryvicki Kirill/0/run.rb
Outdated
puts '' | ||
puts key.capitalize+' is '+recent_price_data['price'].to_s+' BYN in Minsk these days.' | ||
min_price = get_min_price(products[key]) | ||
puts 'Lowest was on '+min_price['year']+'/'+month_map[min_price['month']].to_s+' at price '+min_price['price'].to_s+' BYN' |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator +.
Metrics/LineLength: Line is too long. [128/120]
Hryvicki Kirill/0/run.rb
Outdated
keys.each do |key| | ||
recent_price_data = get_recent_price_data(key, products, month_map) | ||
puts '' | ||
puts key.capitalize+' is '+recent_price_data['price'].to_s+' BYN in Minsk these days.' |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator +.
Hryvicki Kirill/0/run.rb
Outdated
'сентябрь' => 9, | ||
'октябрь' => 10, | ||
'ноябрь' => 11, | ||
'декабрь' => 12, |
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.
Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
result | ||
end | ||
|
||
|
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.
Layout/EmptyLines: Extra blank line detected.
Hryvicki Kirill/0/run.rb
Outdated
def find_max_month(year_hash, max_month_price = 0, max_month = nil) | ||
year_hash.each do |month, month_hash| | ||
price = month_hash['Minsk'] | ||
next unless price |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
def find_min_year(year, min_month_data, min_year_price) | ||
result = {} | ||
min_month_price = min_month_data["price"] | ||
result['month'] = min_month_data["month"] |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def find_min_year(year, min_month_data, min_year_price) | ||
result = {} | ||
min_month_price = min_month_data["price"] |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Hryvicki Kirill/0/run.rb
Outdated
def find_min_month(year_hash, min_month_price = 9_999_999_999_999, min_month = nil) | ||
year_hash.each do |month, month_hash| | ||
price = month_hash['Minsk'] | ||
next unless price |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
if product_data[current_month] | ||
month_key = current_month | ||
else | ||
month_key = product_data.keys.max{ |a,b| month_map[a].to_i <=> month_map[b].to_i } |
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.
Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
Layout/SpaceAfterComma: Space missing after comma.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
file_instance = get_file_instance(file_path) | ||
fetch_products_data(file_instance, products, regions) if file_instance | ||
end | ||
loop do |
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/BlockLength: Block has too many lines. [27/25]
Hryvicki Kirill/0/run.rb
Outdated
file_paths = Dir['./data/*'] | ||
file_paths.each do |file_path| | ||
file_instance = get_file_instance(file_path) | ||
fetch_products_data(file_instance, products, regions) if file_instance |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/run.rb
Outdated
year = data['year'] | ||
month = data['month'] | ||
origin_product = data['product'] | ||
return form_similar_products_array(products, price, year, month, origin_product) |
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.
Style/RedundantReturn: Redundant return detected.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def get_closest_month(current_month, product_data, month_map) | ||
if product_data[current_month] |
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.
Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
Hryvicki Kirill/0/run.rb
Outdated
if product_data[current_year] | ||
year_key = current_year | ||
else | ||
year_key = product_data.keys.max { |a, b| a.to_i <=> b.to_i } |
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.
Performance/CompareWithBlock: Use max_by(&:to_i) instead of max { |a, b| a.to_i <=> b.to_i }.
Hryvicki Kirill/0/run.rb
Outdated
ext = file_path.split('.')[2] | ||
file_instance = nil | ||
if ext == 'xls' || ext == 'xlsx' | ||
file_instance = Roo::Spreadsheet.open(file_path) |
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.
Lint/UselessAssignment: Useless assignment to variable - file_instance.
Hryvicki Kirill/0/loadFiles.rb
Outdated
if /http:\/\/www.belstat.gov.by/ === str_link | ||
f_link = str_link | ||
else | ||
f_link = 'http://www.belstat.gov.by' + str_link |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link = URI.unescape(str_link) | ||
str_link = URI.escape(str_link) | ||
if /http:\/\/www.belstat.gov.by/ === str_link | ||
f_link = str_link |
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.
Layout/IndentationWidth: Use 2 (not 4) spaces for indentation.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link = link.href.to_s | ||
str_link = URI.unescape(str_link) | ||
str_link = URI.escape(str_link) | ||
if /http:\/\/www.belstat.gov.by/ === str_link |
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.
Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.
Performance/RegexpMatch: Use match? instead of === when MatchData is not used.
Style/RegexpLiteral: Use %r around regular expression.
Style/CaseEquality: Avoid the use of the case equality operator ===.
Hryvicki Kirill/0/loadFiles.rb
Outdated
page.links_with(:href => /.xls/).each do |link| | ||
str_link = link.href.to_s | ||
str_link = URI.unescape(str_link) | ||
str_link = URI.escape(str_link) |
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.
Lint/UriEscapeUnescape: URI.escape method is obsolete and should not be used. Instead, use CGI.escape, URI.encode_www_form or URI.encode_www_form_component depending on your specific use case.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
if product_data[current_month] | ||
return month_key = current_month | ||
else | ||
return month_key = product_data.keys.max { |a, b| month_map[a].to_i <=> month_map[b].to_i } |
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.
Style/RedundantReturn: Redundant return detected.
Lint/UselessAssignment: Useless assignment to variable - month_key.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def get_closest_month(current_month, product_data, month_map) | ||
if product_data[current_month] | ||
return month_key = current_month |
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.
Style/RedundantReturn: Redundant return detected.
Lint/UselessAssignment: Useless assignment to variable - month_key.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def get_closest_month(current_month, product_data, month_map) | ||
if product_data[current_month] |
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.
Style/GuardClause: Use a guard clause instead of wrapping the code inside a conditional expression.
Hryvicki Kirill/0/run.rb
Outdated
if product_data[current_year] | ||
return year_key = current_year | ||
else | ||
return year_key = product_data.keys.max { |a, b| a.to_i <=> b.to_i } |
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.
Style/RedundantReturn: Redundant return detected.
Lint/UselessAssignment: Useless assignment to variable - year_key.
Performance/CompareWithBlock: Use max_by(&:to_i) instead of max { |a, b| a.to_i <=> b.to_i }.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def get_closest_year(current_year, product_data) | ||
if product_data[current_year] | ||
return year_key = current_year |
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.
Style/RedundantReturn: Redundant return detected.
Lint/UselessAssignment: Useless assignment to variable - year_key.
Hryvicki Kirill/0/run.rb
Outdated
product_month_data = product_year_data[year_key] | ||
month_key = get_closest_month(current_month, product_month_data, month_map) | ||
return { 'price' => product_month_data[month_key]['Minsk'], 'year' => year_key, | ||
'month' => month_key, 'product' => key } |
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.
Layout/AlignHash: Align the elements of a hash literal if they span more than one line.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link | ||
else | ||
'http://www.belstat.gov.by' + str_link | ||
end |
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.
Layout/EndAlignment: end at 16, 2 is not aligned with if at 12, 11.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link = WEBrick::HTTPUtils.escape(str_link) | ||
f_link = if %r{http:\/\/www.belstat.gov.by}.match?(str_link) | ||
str_link | ||
else |
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.
Layout/ElseAlignment: Align else with if.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link = WEBrick::HTTPUtils.unescape(str_link) | ||
str_link = WEBrick::HTTPUtils.escape(str_link) | ||
f_link = if %r{http:\/\/www.belstat.gov.by}.match?(str_link) | ||
str_link |
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.
Layout/IndentationWidth: Use 2 (not -7) spaces for indentation.
Hryvicki Kirill/0/loadFiles.rb
Outdated
|
||
agent = Mechanize.new | ||
page = agent.get('http://www.belstat.gov.by/ofitsialnaya-statistika/makroekonomika-i-okruzhayushchaya-sreda/tseny/operativnaya-informatsiya_4/srednie-tseny-na-potrebitelskie-tovary-i-uslugi-po-respublike-belarus') | ||
page.links_with(:href => /.xls/).each do |link| |
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.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def form_recent_price_data(price, year, month, product) | ||
{ |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
end | ||
end | ||
|
||
def get_recent_price_data(key, products, month_map) |
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/AbcSize: Assignment Branch Condition size for get_recent_price_data is too high. [15.68/15]
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
end | ||
|
||
def parse_month(month_map) | ||
month_map.each { |month, month_number| current_month = month if month_number == current_month } |
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.
Lint/UselessAssignment: Useless assignment to variable - current_month.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def get_recent_price_data(key, products, month_map) | ||
current_year = Time.now.strftime('%Y').to_s | ||
current_month = Time.now.strftime('%m') |
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.
Lint/UselessAssignment: Useless assignment to variable - current_month.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
def get_recent_price_data(key, products, month_map) | ||
current_year = Time.now.strftime('%Y').to_s | ||
current_month = parse_month(month_map) | ||
product_year_data = products[key]; |
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.
Style/Semicolon: Do not use semicolons to terminate expressions.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/loadFiles.rb
Outdated
str_link = link.href.to_s | ||
str_link = WEBrick::HTTPUtils.unescape(str_link) | ||
str_link = WEBrick::HTTPUtils.escape(str_link) | ||
f_link = if %r{http:\/\/www.belstat.gov.by}.match?(str_link) |
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.
можно проще) str_link.start_with?('/')
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.
Заменил
Hryvicki Kirill/0/run.rb
Outdated
file_instance = nil | ||
if ext == 'xls' || ext == 'xlsx' | ||
Roo::Spreadsheet.open(file_path) | ||
file_instance = conditiona_load(ext, file_path) |
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.
Очепятки
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.
Исправлено
Hryvicki Kirill/0/run.rb
Outdated
ext = file_path.split('.')[2] | ||
file_instance = nil | ||
if ext == 'xls' || ext == 'xlsx' | ||
Roo::Spreadsheet.open(file_path) |
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.
бесполезная строка
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.
Удалено
Hryvicki Kirill/0/run.rb
Outdated
|
||
def find_keys(word, products) | ||
result = [] | ||
products.keys.each { |key| |
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.
можно использовать select, и обойтись без объявления result
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.
Сделано
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def fetch_products_data(file_instance, products, regions) | ||
for n in 9..file_instance.last_row |
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.
Enumerable.drop(9), iterate over rows.
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.
Заменил на (9..file_instance.last_row).each do |n|
Hryvicki Kirill/0/run.rb
Outdated
end | ||
end | ||
|
||
def add_product(products, key, year, month, regions, file_instance, n) |
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.
вынеси парсинг в отдельный метод
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.
Сделано
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def get_min_price(hash) | ||
min_year_price = 9_999_999_999_999 |
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.
Нельзя так делать. Ты недооцениваешь грядущую инфляцию белорусского рубля)
Есть Float::INFINITY, но лучше вычислить минимум вызовом .min на масиве с нужными данными
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.
Заменил на Float::INFINITY
Hryvicki Kirill/0/run.rb
Outdated
'ноябрь' => 11, | ||
'декабрь' => 12 | ||
} | ||
regions = ['Brest', 'Vitebsk', 'Gomel', 'Grodno', 'Minsk', 'Minsk Region', 'Mogilyov'] |
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.
оберни весь исполняемый код в медот main
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.
Сделано
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
result | ||
end | ||
|
||
def main() |
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/AbcSize: Assignment Branch Condition size for main is too high. [63.04/15]
Metrics/MethodLength: Method has too many lines. [48/10]
Style/DefWithParentheses: Omit the parentheses in defs when the method doesn't accept any arguments.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/run.rb
Outdated
loop do | ||
puts 'What price are you looking for?' | ||
word = gets.chomp.downcase.encode('UTF-8') | ||
keys = $products.keys.select { |key| key.include?(word) } |
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.
Style/GlobalVars: Do not introduce global variables.
end | ||
end | ||
|
||
def main |
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/AbcSize: Assignment Branch Condition size for main is too high. [20.25/15]
Metrics/MethodLength: Method has too many lines. [17/10]
Hryvicki Kirill/0/run.rb
Outdated
|
||
def second_level_max_price(key) | ||
max_price = get_max_price($products[key]) | ||
puts 'Maximum was on ' + max_price['year'] + '/' + $month_map[max_price['month']].to_s + ' at price ' |
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.
Style/GlobalVars: Do not introduce global variables.
Hryvicki Kirill/0/run.rb
Outdated
end | ||
|
||
def second_level_max_price(key) | ||
max_price = get_max_price($products[key]) |
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.
Style/GlobalVars: Do not introduce global variables.
Hryvicki Kirill/0/run.rb
Outdated
print min_price['price'].to_s + ' BYN' | ||
end | ||
|
||
def second_level_max_price(key) |
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/AbcSize: Assignment Branch Condition size for second_level_max_price is too high. [15.03/15]
Hryvicki Kirill/0/run.rb
Outdated
result | ||
end | ||
|
||
def init_variables |
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/MethodLength: Method has too many lines. [21/10]
Hryvicki Kirill/0/run.rb
Outdated
|
||
def form_similar_products_array( price, year, month, origin_product) | ||
result = [] | ||
$products.each do |product, product_data| |
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.
Style/GlobalVars: Do not introduce global variables.
Hryvicki Kirill/0/run.rb
Outdated
form_similar_products_array( price, year, month, origin_product) | ||
end | ||
|
||
def form_similar_products_array( price, year, month, origin_product) |
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.
Layout/SpaceInsideParens: Space inside parentheses detected.
Hryvicki Kirill/0/run.rb
Outdated
year = data['year'] | ||
month = data['month'] | ||
origin_product = data['product'] | ||
form_similar_products_array( price, year, month, origin_product) |
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.
Layout/SpaceInsideParens: Space inside parentheses detected.
Hryvicki Kirill/0/run.rb
Outdated
|
||
def get_closest_month(current_month, product_data) | ||
current_month if product_data[current_month] | ||
product_data.keys.max { |a, b| $month_map[a].to_i <=> $month_map[b].to_i } unless product_data[current_month] |
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.
Style/GlobalVars: Do not introduce global variables.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
Hryvicki Kirill/0/Gemfile
Outdated
source "https://rubygems.org" | ||
|
||
gem 'mechanize' | ||
gem 'roo' |
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.
Layout/TrailingWhitespace: Trailing whitespace detected.
Hryvicki Kirill/0/Gemfile
Outdated
@@ -0,0 +1,5 @@ | |||
source "https://rubygems.org" |
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.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
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.
Some files could not be reviewed due to errors:
Error: We found some problems with your configuration file: [/IrresponsibleMo...
Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined.
products = make_products_container | ||
loop do | ||
keys = user_wish(products) | ||
puts word.capitalize + ' can not be found in database' if keys.empty? |
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.
дважды проверяется одно условие. лучше так
if keys.empty?
puts ...
next
end
...
products.keys.select { |key| key.include?(word) } | ||
end | ||
|
||
def month_map_former |
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.
не нужен метод, можно обойтись константой
end | ||
|
||
def first_level(key, recent_price_data) | ||
puts '' |
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.
just
puts
|
||
def form_similar_products_array(products, price, year, month, origin_product) | ||
result = [] | ||
products.each do |product, product_data| |
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.
products.select
и не понадобится result
result | ||
end | ||
|
||
def find_max_month(year_hash, max_month_price = 0, max_month = nil) |
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.
последние два параметра не нужны, объяви переменные в методе
а лучше используй select, max_by
end | ||
|
||
def find_min_month(year_hash, min_month_price = Float::INFINITY, min_month = nil) | ||
year_hash.each do |month, month_hash| |
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.
параметры не нужны, объяви переменные внутри метода
end | ||
|
||
def get_closest_month(current_month, product_data, month_map) | ||
current_month if product_data[current_month] |
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.
если не имелось в виду return current_month if то строка бесполезна
end | ||
|
||
def get_closest_year(current_year, product_data) | ||
current_year if product_data[current_year] |
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.
строка бесполезна
|
||
def parse_month(month_map) | ||
current_month = Time.now.strftime('%m') | ||
month_map.each { |month, month_number| current_month = month if month_number == current_month } |
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.
==
Name
Kirill Hryvicki
Homework#
0
Link to video with demo
Comment
All levels