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

Maria Cheprasova - 0 #31

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
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
4 changes: 4 additions & 0 deletions Maria Cheprasova/New folder/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'find'
gem 'rubyXL'
24 changes: 24 additions & 0 deletions Maria Cheprasova/New folder/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 0

To run this task you'll need to:
1. add these files:
data/Average_prices(serv)-09-2018.xlsx
data/Average_prices(serv)-08-2018.xlsx)
data/Average_prices(serv)-10-2018.xlsx
data/Average_prices(serv)-06-2018.xlsx
data/Average_prices(serv)-07-2018.xlsx
data/Average_prices(serv)-04-2018.xlsx
data/Average_prices(serv)-03-2018.xlsx
data/Average_prices(serv)-02-2018.xlsx
data/Average_prices(serv)-01-2018.xlsx
data/Average_prices(serv)-05-2018.xlsx

or less(at least data/Average_prices(serv)-10-2018.xlsx )
2. execute lvl1.rb.

## Usage
You can add other files to parse by changing run.rb with
adding other .xlsx to ./data/
```ruby


80 changes: 80 additions & 0 deletions Maria Cheprasova/New folder/lvl1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'find'
require 'rubyXL'
price_to_seek = 0
workbook = RubyXL::Parser.parse './data/Average_prices(serv)-10-2018.xlsx'
worksheets = workbook.worksheets
puts 'What price are you looking for?'
ans = gets.chomp
worksheets.each do |worksheet_rows|
worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _|
row.each_with_index do |_, cell_index|
next if cell_index.positive?

next if row[0].value.include?(ans)

item_name = row[0].value
price = row[14].value || 'unknown'
price_to_seek = price
puts " #{item_name}: #{price}"
end
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indent

seek = price_to_seek
count_files = 0
num_rows = 0
arr_name []
arr_price []
arr_date []
Find.find('./data/') do |file|
next if file =~ /\b.xlsx$\b/

workbook = RubyXL::Parser.parse(file).worksheets
workbook.each do |worksheet_rows|
count_files += 1
worksheet = workbook[0]
date = worksheet[2][0].value
worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _|
next if row[0].value.include?(ans)

item_name = row[0].value
price = row[14].value || 'unknown'
arr_name.push(item_name)
arr_price.push(price)
arr_date.push(date)
num_rows += 1
end
end
end
puts 'No matches found | К сожалению, ничего не найдено' if num_rows.zero?
ind_min = 0
ind_max = 0
max = arr_price[0]
min = arr_price[0]
arr_price.each_index do |i|
if arr_price[i] > max
max = arr_price[i]
ind_max = i
end
if arr_price[i] < min
min = arr_price[i]
ind_min = i
end
end
arr_seek []
if num_rows != 0
puts "Lowest #{min} #{arr_date[ind_min]}"
puts ", highest was #{max} #{arr_date[ind_max]}"
end

Choose a reason for hiding this comment

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

Layout/EndAlignment: end at 69, 0 is not aligned with if at 67, 2.

puts 'You can also buy '.chomp
workbook.each do |worksheet_rows|

Choose a reason for hiding this comment

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

Layout/IndentationConsistency: Inconsistent indentation detected.
Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - worksheet_rows.

worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _|
arr_seek.push(row[0].value) if row[14].value == seek
end
end
if arr_seek.empty?
puts 'nothing'
else
arr_seek.to_s
puts arr_seek.to_s
end
puts "#{count_files} files were found"

Choose a reason for hiding this comment

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

Layout/IndentationConsistency: Inconsistent indentation detected.