-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2391768
commit 89a5db0
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'roo' | ||
|
||
# Class of finding products | ||
class Finder | ||
def initialize | ||
@a = Roo::Spreadsheet.open 'file1.xlsx' | ||
@answer = gets.chomp.upcase | ||
@result = [] | ||
end | ||
|
||
def making_a_product_list | ||
@array1 = @a.sheet(0).column(1) | ||
@array2 = @a.sheet(0).column(15) | ||
@list = {} | ||
|
||
(0...@array1.length).each do |i| | ||
@list.store(@array1[i], @array2[i]) | ||
end | ||
@list.delete_if { |_k, v| v.nil? } | ||
end | ||
|
||
def searcher | ||
making_a_product_list | ||
@list.each do |k, v| | ||
@result.push("The #{k} is #{v} BYN in Minsk these days") if k.to_s.include? @answer | ||
end | ||
puts @result | ||
print "#{@answer} can not be found in our data base !" if @result[0].nil? | ||
end | ||
end | ||
|
||
puts 'What product do you need ?' | ||
Finder.new.searcher |